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

feat: interactive env:encrypt & env:decrypt #53081

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public function handle()
{
$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

}

if (! $key) {
$this->fail('A decryption key is required.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}';
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.


/**
* The console command description.
Expand Down Expand Up @@ -62,6 +63,10 @@ public function handle()

$key = $this->option('key');

if (! $key && $this->option('interactive')) {
$key = $this->ask('Encryption key');
}

$keyPassed = $key !== null;

$environmentFile = $this->option('env')
Expand Down