-
Notifications
You must be signed in to change notification settings - Fork 11k
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
feat: interactive env:encrypt & env:decrypt #53081
feat: interactive env:encrypt & env:decrypt #53081
Conversation
@@ -62,6 +62,10 @@ public function handle() | |||
{ | |||
$key = $this->option('key') ?: Env::get('LARAVEL_ENV_ENCRYPTION_KEY'); | |||
|
|||
if (! $key) { | |||
$key = $this->ask('Decryption key'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe better to use https://laravel.com/docs/11.x/prompts#password
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea, have changed this now
@@ -22,7 +22,8 @@ class EnvironmentEncryptCommand extends Command | |||
{--cipher= : The encryption cipher} | |||
{--env= : The environment to be encrypted} | |||
{--prune : Delete the original environment file} | |||
{--force : Overwrite the existing encrypted environment file}'; | |||
{--force : Overwrite the existing encrypted environment file} | |||
{--interactive : Prompt the encryption key}'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should just use $this->input->isInteractive()
instead of adding new option. https://github.com/symfony/console/blob/7.1/Input/InputInterface.php#L125
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did not know the existence of this one. Have used that instead. However, I've then also added a select
prompt since I do want the interactive user to be able to opt for a generated key instead of having to provide one. This will however change the current interactive command line experience. Not sure if that would be a problem.
* feat: add interactive mode for env:encrypt & env:decrypt * style: remove whitespace changes * feat: use password prompt & isInteractive() * style: added end of line comma in array * test: change/provide tests for interactive mode * style: remove empty line * formatting --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
When using
env:encrypt
and especiallyenv:decrypt
, it was bugging me that I had to provide the encryption key in the command line and it therefore ended up in my command line history. I did not want to use the LARAVEL_ENV_ENCRYPTION_KEY environment variable as I do not want the encryption key to be stored on the development machine.Hereby a PR to add a simple interactive mode for
env:descrypt
that wouldask()
for the decryption key and prevent it from ending up in history. Forenv:encrypt
I added an--interactive
option to not break the current behavior of automatically generating an encryption key.