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

[5.4] Require confirmation for key:generate when changing key in production mode #16804

Merged
merged 1 commit into from
Dec 14, 2016
Merged
Changes from all 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
Require confirmation for key:generate when changing key in production…
… mode
  • Loading branch information
polybuildr committed Dec 14, 2016
commit e7b5437fedda3c7963a8b268fa4b615f308322e6
19 changes: 16 additions & 3 deletions src/Illuminate/Foundation/Console/KeyGenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
namespace Illuminate\Foundation\Console;

use Illuminate\Console\Command;
use Illuminate\Console\ConfirmableTrait;

class KeyGenerateCommand extends Command
{
use ConfirmableTrait;

/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'key:generate {--show : Display the key instead of modifying files}';
protected $signature = 'key:generate
{--show : Display the key instead of modifying files}
{--force : Force the operation to run when in production}';

/**
* The console command description.
Expand All @@ -36,7 +41,9 @@ public function fire()
// Next, we will replace the application key in the environment file so it is
// automatically setup for this developer. This key gets generated using a
// secure random byte generator and is later base64 encoded for storage.
$this->setKeyInEnvironmentFile($key);
if (! $this->setKeyInEnvironmentFile($key)) {
return;
}

$this->laravel['config']['app.key'] = $key;

Expand All @@ -47,15 +54,21 @@ public function fire()
* Set the application key in the environment file.
*
* @param string $key
* @return void
* @return bool
*/
protected function setKeyInEnvironmentFile($key)
{
$currentKey = $this->laravel['config']['app.key'];
if (strlen($currentKey) !== 0 && (! $this->confirmToProceed())) {
return false;
}
file_put_contents($this->laravel->environmentFilePath(), str_replace(
'APP_KEY='.$this->laravel['config']['app.key'],
'APP_KEY='.$key,
file_get_contents($this->laravel->environmentFilePath())
));

return true;
}

/**
Expand Down