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

support variable when sourcing payload from file #1731

Closed
1 task
teto opened this issue Jul 6, 2023 · 12 comments · Fixed by #2295
Closed
1 task

support variable when sourcing payload from file #1731

teto opened this issue Jul 6, 2023 · 12 comments · Fixed by #2295
Labels
enhancement New feature or request topic: generators
Milestone

Comments

@teto
Copy link
Contributor

teto commented Jul 6, 2023

Problem to solve

I would like to be able to use a variable in the statement referencing an external payload
file,{{TEST_DATA_FOLDER}}/v2/payload.json;

but that doesn't seem supported at the moment.

Proposal

Interpolate .env variables in the file,<path> statement

Additional context and resources

I am a user/maintainer of https://github.com/rest-nvim/rest.nvim and I would be ready to have rest.nvim format converge to hurl's format that looks easier to parse with e.g., tree-sitter. rest-nvim/rest.nvim#195 .
rest.nvim has some advantages over hurl.nvim (can run per-request, I can select their order interactively etc) but hurl is more robust. I would like to be able to use both tools on the same file (or the ability to export/import from both formats easily).

Tasks to complete

  • ...
@teto teto added the enhancement New feature or request label Jul 6, 2023
@jcamiel
Copy link
Collaborator

jcamiel commented Jul 6, 2023

Hi @teto, at least reading our grammar it should be actually supported => https://hurl.dev/docs/grammar.html#filename 😅

Yet, we haven't implemented it. See also #464 with the same issue. We should really implement it asap!

@teto
Copy link
Contributor Author

teto commented Jul 6, 2023

feel free to close as duplicate then. when you mention a grammar, there is no tree-sitter grammar implemented yet ? I ask because I've written one (incomplete) for rest.nvim but it's nice to list query, filter them etc. The way hurl is used, I dont think it's necessary but that might be a fun project if someone wanna play with tree-sitter :)

@jcamiel
Copy link
Collaborator

jcamiel commented Jul 7, 2023

We've have to work around tooling, a tree-sitter parser is certainly on our radar! No work has started yet though.

@teto
Copy link
Contributor Author

teto commented Jul 7, 2023

Is there a reason why absolute paths can't be used ?

$ hurl v2/trial.hurl --variables-file .env
error: Unauthorized file access
   --> v2/trial.hurl:8:6
    |
  8 | file,/home/teto/test/data/payloads/v2/ComputationalModel.json;
    |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unauthorized access to file /home/teto/test/data/payloads/v2/ComputationalModel.json, check --file-root option

It works with --file-root but still I was surprised :)

EDIT: I have other requests that contain fullpaths and hurl didn't complain then :/ the first file exists, I dont understand why it didn't work the first time

@jcamiel
Copy link
Collaborator

jcamiel commented Jul 7, 2023

We have make this constraint for security reason. If the included file is in a children directory of the Hurl file parent folder, file inclusion should work without --file-root. If you want to include files that are in a very different directory (let's say for instance /etc/passwd) you have to explicitly use --file-root (unless there is a bug of course)

@teto
Copy link
Contributor Author

teto commented Jul 8, 2023

about the treesitter grammar, there is already one actually ^^'
https://github.com/pfeiferj/tree-sitter-hurl/

@ppaulweber
Copy link
Contributor

@jcamiel is there any update in using and loading a file-based content (e.g. for the request body or only a JSON value) in a hurl request specification?

@jcamiel
Copy link
Collaborator

jcamiel commented Sep 19, 2023

Hi @ppaulweber you can use a file body now (see https://hurl.dev/docs/request.html#file-body)
For instance, you can send a JSON body with this kind of file:

POST https://example.org/api/foo
Content-Type: application/json
file,data.bin;
HTTP 201

Do you have something else in mind (or needs)?

@ppaulweber
Copy link
Contributor

@jcamiel great, thx for the quick reply ... yes, my use case would be more in the sense to include a file contents as e.g. JSON string value in the form of:

POST https://example.org/api/foo
{
    "key": {{file,data.bin;}}
}
HTTP 200

The problem with using just directly variables is on the newline and escape encoding in the variable string itself. Therefore, a "include" or "file load" on specific positions in the JSON payload would be one of my current needs.

@jcamiel
Copy link
Collaborator

jcamiel commented Sep 19, 2023

OK, that's very clear. We have already filters that allow to transform value and we have in mind kind of "generators" to create/inject data (like random data or file inclusion in JSON parts). That will address your use case, we just need to prioritize it.

@ppaulweber
Copy link
Contributor

@jcamiel perfect, good to know ... let me know if I can help out with the implementation or is there already a dedicated issue or PR for this?

@jcamiel
Copy link
Collaborator

jcamiel commented Sep 19, 2023

Thanks, first we need to state and finalize what will be the syntax (and what we can support for generators). I'll link here the PR/issues as soon as we advance.

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

Successfully merging a pull request may close this issue.

3 participants