etauker / insomnia-plugin-system-env

Insomnia plugin for accessing system environment variables
5 stars 2 forks source link

Insomnia is not able to recognize mac's environment variables - 2 #2

Open gelato-piotr-rozmarynowski opened 3 years ago

gelato-piotr-rozmarynowski commented 3 years ago

Hi @etauker, Regarding to the closed issue: https://github.com/etauker/insomnia-plugin-system-env/issues/1

I have added custom variables to my ~/.zshrc and ~/.bash_profile. They are output correctly when executing env command. But unfortunately, Insomnia cannot fetch them, only when I run the app through the terminal. Is there a way to run Insomnia using mac UI instead of the terminal command to have the environment variables automatically loaded? Maybe the option would be to add some configurable input field to provide a path to a file with custom variables? Thanks!

etauker commented 3 years ago

Hi @gelato-piotr-rozmarynowski,

My original goal was to make this accessible through the UI. Unfortunately after looking into it I was not able to find a solution and running insomnia from the command line was a suitable workaround for me.

The issue is that when you open a terminal window, ~/.zshrc, ~/.bash_profile and other dotfiles only get sourced into that shell, the parent shell variables does not get changed. When you open an application from the UI, it is spawned from the parent shell and the dotfiles do not get sourced. This is done by design for security reasons so I don't imagine there are ways to bypass it without any insecure and unreliable hacks.

The workaround you suggested could work and there is another plugin that does this already (and there may be others that also do something similar). Have a look and if that's not suitable for what you need let me know and I'll see how I can add the required logic to my plugin.

Sidenote: insomnia does not yet expose any hooks for application startup so any plugin that reads files has to do so on every request and every template variable edit. Just something to keep in mind if you expect to have large env files or a slow file system.

Thanks for the interest, etauker

gelato-piotr-rozmarynowski commented 3 years ago

Thank you @etauker for the reply. I will check the dotenv plugin out and come back to you with the info if the issue gets resolved and how.