-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
VSCode Evaluate Selection Fails #1505
Comments
The VS Code plugin uses See |
Hey Torin, thx for the response. That makes perfect sense ... except the behaviour of opa eval in a terminal within VSCode is different to that when using evaluate selection within the editor. Let me explain, I'll cut everything down to a bare minimum.... The POLICY file: C:\Data\opa\validate_labels_policy.rego
The policy TEST file: C:\Data\opa\validate_labels_test.rego
The data file: C:\Data\opa\nginx_demo_deploy.yaml
Using opa eval from a TERMINAL within VSCode (in this case a cmd terminal - but its the same if I choose wsl). First I ask for an eval of everything in 'data' ... and sure enough the whole of the nginx_demo_deploy.yaml file has been loaded, and no reference to 'c'
If I then ask for an eval of data.kind ... it should return 'Deployment' ... and sure enough it does
Now switch to the VSCode editor pane with the POLICY file validate_labels_policy.rego open. Again this file on the file-system is in C:\Data\opa\validate_labels_policy.rego and C:\Data\opa is my current directory. As above, I will highlight 'data' on the first line of the allow block: allow = true { In the output.json pane I see (straight-away we see the 'c' ....
... and if I then highlight data.kind, I get No results
Drop down a line, and highlight data.c.kind ...
So, I still don't understand the difference between opa eval at the terminal and opa eval being called via the VSCode extension ? It makes sense that specifying the policy rule WITHOUT the 'c' works because that is using the opa executable like the terminal. What am I missing. How can I configure the extension in VSCode to behave in the same way as running opa at the command-line ? Regards Fraser. |
Hrmmm. That's odd. When you select
This returns the value of all the JSON/YAML on disk as well as all values generated by rules in .rego files on disk. For some reason, the Is your VS Code workspace opened inside |
OK. I was able to easily reproduce the problem inside a Windows VM. If you run the following command, it will output the same value you see in VS Code.
The problem appears to be with how the file loader in OPA deals with Windows paths. |
Ok, a bit more info ... In the terminal I was actually running from the directory where the data file is located, so I didn't provide the full path. If I do provide the full path, the data is located under 'c' like it is in the editor. So presumably the extension is resolving the absolute path and that is why it also put the data under 'c'.
|
Ah, looks like our updates crossed and we both found the same explanation. I see that you have changed this to type ‘bug’, so I’ll wait for the patched version, but workaround it for now. Thanks for the swift response. Fraser. |
The file loader splits paths on the first colon character and uses the left-hand side for the prefix to root the document at under data. On windows this is problematic because of drive lettesr (e.g., C:\X\Y\Z is interpreted as load file at \X\Y\Z under data.C. This change updates the loader to accept file:// URLs. This way callers can unambiguously specify filenames that contain colon characters. For now this will mainly be used by VS Code and other programmatic callers. In future we can support other schemes (e.g., http). Fixes open-policy-agent#1505 Signed-off-by: Torin Sandall <torinsandall@gmail.com>
The OPA extension for VS code has been updated to use |
Expected Behavior
Actual Behavior
Steps to Reproduce the Problem
nginx_demo_deploy.yaml
validate_labels_policy.rego
Unit tests work successfully. I can toggle PASS and FAIL by altering either the input YAML or the policy, so it would appear that the policy can find data.kind and metadata.labels.app
The output.json pane shows the following (why the outer "c" level ??)
// No results found.
allow = true {
data.c.kind == "Deployment"
The highlight and evaulate that selection the correct data is returned in output.json, but then the test FAILs:
Why does the extra "c" level appear within data, and how can I get rid of it so that evaluate selection works correctly ?
Additional Info
OPA Extension version: 0.2.4
OPA version:
Platform: Windows 10 Prof : 1809
The text was updated successfully, but these errors were encountered: