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

Question: Where does ps-dotenv persist white lists? #6

Open
jhholm opened this issue Sep 6, 2024 · 1 comment
Open

Question: Where does ps-dotenv persist white lists? #6

jhholm opened this issue Sep 6, 2024 · 1 comment

Comments

@jhholm
Copy link

jhholm commented Sep 6, 2024

I'm currently not sure if I'm using Approve-DotenvDir and Approve-DotenvFile correctly as it seems that the approvals are not persisted between terminal sessions.

I suppose this should work

  1. Open a new PowerShell terminal
  2. Create a new .env file e.g. echo FOO=BAR > c:\myexampledirectory.env
  3. Approve the folder/file e.g. Approve-DotenvDir c:\myexampledirectory
  4. Close the terminal
  5. Open a new terminal
  6. CD to the directory with the approved .env file e.g. cd c:\mygitdirectory
  7. Environment variable FOO should be loaded from the .env file

So step 7 doesn't work. I get an error message "file is not authorized, authorize it with Approve-DotenvFile or disable the safe mode". To get past this error, I would need to approve the file again.

To circumvent this I added my example directory to be approved in my $profile.

My $profile regarding dotenv

Import-Module Dotenv
Approve-DotenvDir C:\myexampledirectory
Enable-Dotenv

Am I overthinking this and something is just breaking the persistence of the approval? Or does the approval need to be run explicitly every time? I think direnv only requires reapproval if you make any changes to the file.

@insomnimus
Copy link
Owner

Hi!
Dotenv doesn't persist any settings as you've guessed.
I've considered having a state/config file, but concluded that the Powershell profile is essentially that, although adding persistent allows is slightly less convenient with it.

I can add this feature if you think others would want it, though I can't give a deadline (I'm rather busy with work these days).

I can think of 2 ways this could be introduced:

  • An inherent state file that lives somewhere in some file, e.g. ~/.dotenv.state
  • A user-provided state file path:
    • The user would have to tell the module where to find it; maybe in a new cmdlet like Register-DotenvStateFile (or maybe a parameter to Update-Dotenv)
    • Dotenv could remember the first time it was specified and load it within Update-Dotenv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants