Skip to content

Conversation

@hhermsen
Copy link
Contributor

@hhermsen hhermsen commented Oct 9, 2024

When using env:encrypt and especially env: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 would ask() for the decryption key and prevent it from ending up in history. For env:encrypt I added an --interactive option to not break the current behavior of automatically generating an encryption key.

$key = $this->option('key') ?: Env::get('LARAVEL_ENV_ENCRYPTION_KEY');

if (! $key) {
$key = $this->ask('Decryption key');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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

{--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}';
Copy link
Member

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

Copy link
Contributor Author

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.

@taylorotwell taylorotwell marked this pull request as draft October 9, 2024 19:42
@hhermsen hhermsen marked this pull request as ready for review October 10, 2024 06:58
@taylorotwell taylorotwell merged commit 6e951b7 into laravel:11.x Oct 10, 2024
31 checks passed
timacdonald pushed a commit to timacdonald/framework that referenced this pull request Oct 15, 2024
* 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>
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

Successfully merging this pull request may close these issues.

3 participants