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

Use a command for variables value #1

Open
remche opened this issue Apr 14, 2023 · 2 comments
Open

Use a command for variables value #1

remche opened this issue Apr 14, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@remche
Copy link

remche commented Apr 14, 2023

Congrats for the great work on this plugin !

Would it be worth considering to use a command for the json variables values ? ie something like :

{
  "dev": {
    "base_url": "http://localhost:3000",
    "jwt_token": $(gopass show pass/mytoken)
  },
  "prod": {
    "base_url": "https://foobar.eu-west.some-cloud.com",
    "jwt_token": "SECRET"
  }
}
@blacklight
Copy link
Owner

blacklight commented Apr 14, 2023

That's an interesting proposal, and I definitely see the use case. However, I'm a bit skeptical about the specific implementation for two reasons:

  1. It would break the JSON specification, and therefore the compatibility with the REST clients on VSCode, IntelliJ, Postman and the likes.
  2. It would open the doors to potential command injection, especially when the command can contain references to external variables - and let's not even get started on everything that can go wrong when parsing the command or injecting its output into the JSON...

Perhaps this could work better if implemented through standard shell environment variables. Two possible ways to implement it:

  1. The simple way - you run export jwt_token="$(gopass show pass/mytoken)" before running neovim, and the existing environment variables are joined to the lookup map, so you can use ${jwt_token} in your requests. Support for .env files is also on my roadmap, but I don't think it would solve your specific use-case - you need dynamic, not static variables.
  2. With custom pre-request scripts - defined either per-environment or on global level. Something along the lines of:
{
  "dev": {
    "__before__": "scripts/setup.dev.sh",
    "base_url": "http://localhost:3000"
  }
}

Then scripts/setup.dev.sh would look like this:

export jwt_token="$(gopass show pass/mytoken)"

This would actually be quite powerful because it would enable to run any custom logic before a request (not only variables), and it may also allow for an __after__ script that can e.g. cleanup things after a request.

How would you consider these options?

@blacklight blacklight added the enhancement New feature or request label Apr 14, 2023
@remche
Copy link
Author

remche commented Apr 17, 2023

@blacklight thanks for the feedback, I totally agree that my proposed implementation is not relevant, it was more to get the idea.

In my workflow, the first and easiest implementation is the best : I use a "lightweight workspace manager" (https://github.com/jamesob/desk), in fact mainly a bunch of shell script setting environment variables. I can rely on this variables to pimp the JSON.

@blacklight blacklight self-assigned this May 9, 2023
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

2 participants