Skip to content

Unable to read default env variables #308

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

Closed
radvil opened this issue Mar 18, 2024 · 7 comments · Fixed by #303
Closed

Unable to read default env variables #308

radvil opened this issue Mar 18, 2024 · 7 comments · Fixed by #303
Labels
bug Something isn't working v2 rest.nvim v2 issues

Comments

@radvil
Copy link

radvil commented Mar 18, 2024

[rest.nvim] WARN: The variable 'BASE_URL_V3' was not found in the document or in the environment. Returning the string as received ...

Here is my ENV config located in the same directory as the *.http file that ran this command

BASE_URL_V3=https://api.themoviedb.org/3
READ_ACCESS_TOKEN=my-access-token-xxx

And following is the request

GET {{BASE_URL_V3}}/movie/popular?language=en-US&page=1
Content-Type: application/json
Authorization: Bearer {{READ_ACCESS_TOKEN}}
@NTBBloodbath
Copy link
Member

Oh woops, I think it is a problem with the implementation. Currently it works with a path relative to where Neovim was opened, Does it work for you if your current working directory is where your files are?

I didn't notice that error because I have an autocommand that modifies my cwd in Neovim, thanks for reporting it 😅

@NTBBloodbath NTBBloodbath added bug Something isn't working v2 rest.nvim v2 issues labels Mar 18, 2024
@radvil
Copy link
Author

radvil commented Mar 18, 2024

Oh woops, I think it is a problem with the implementation. Currently it works with a path relative to where Neovim was opened, Does it work for you if your current working directory is where your files are?

I didn't notice that error because I have an autocommand that modifies my cwd in Neovim, thanks for reporting it 😅

Humm, I try to cd into the file's cwd and opened the http file and it's still happen, the output vim.loop.cwd() of shows that I am at the file's directory already. Did I do it wrong ?

@NTBBloodbath
Copy link
Member

That's odd. Does it happen if you try to manually load the environment variables file with :lua require("rest-nvim.parser.env_vars").read_file(false)? If the function ran without errors you can check if the variable is loaded by using :=vim.env.BASE_URL_V3 and it shouldn't return nil

@radvil
Copy link
Author

radvil commented Mar 19, 2024

That's odd. Does it happen if you try to manually load the environment variables file with :lua require("rest-nvim.parser.env_vars").read_file(false)? If the function ran without errors you can check if the variable is loaded by using :=vim.env.BASE_URL_V3 and it shouldn't return nil

Oh yeah, running the command manually inside the http file dir seems to works just fine, but seems like it doesn't read my Authorization header (still with the same setup as above). Following is the output when I go the next pane (Headers)

Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Date: Tue, 19 Mar 2024 15:59:12 GMT
Server: openresty
Cache-Control: public, max-age=300
X-Cache: Error from cloudfront
Via: 1.1 7aabf4a3a1d35735380ea2b24910ae5e.cloudfront.net (CloudFront)
X-Amz-Cf-Pop: CGK51-P3
Alt-Svc: h3=":443"; ma=86400
X-Amz-Cf-Id: GQ5f0rbNyYLuKaJEXKm1L9gwjrQ6JTWtIn5jrKqHC3_oTPmPdtFc3Q==
Vary: Origin

And following is the response I got by running the same file:

GET https://api.themoviedb.org/3/movie/popular?language=en-US&page=1
HTTP/1.1 401 Unauthorized

#+RES
{
  "status_code": 7,
  "status_message": "Invalid API key: You must be granted a valid key.",
  "success": false
}
#+END

The Authorization Header seems missing, IDK whether it was me who did it wrong ??

@NTBBloodbath
Copy link
Member

NTBBloodbath commented Mar 19, 2024

Oh yeah, running the command manually inside the http file dir seems to works just fine

Oh yes, I just found a small bug in the last refactor I did regarding the handling of .env, I'm pushing it now :)

The Authorization Header seems missing, IDK whether it was me who did it wrong ??

I think in the rewrite I forgot to add support for authentication (which didn't exist in v1 either, perhaps that's why it didn't was in my list), but I'm already reading the lua-curl code to add support for it, it shouldn't take me long.

Edit: could you please open a separate issue for the Authentication issues? That way it would be more organized and I can keep track of everything 🙂

@radvil
Copy link
Author

radvil commented Mar 19, 2024

yeah sure, this safe to close rn.

@VesperQuartz
Copy link

Mine only worked when i put quotes around it, Why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v2 rest.nvim v2 issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants