mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2024-12-15 06:09:58 +08:00
Use built-in key:generate
command
This commit is contained in:
parent
eed205b7f9
commit
29ce9d3df1
@ -37,7 +37,7 @@ jobs:
|
||||
- vendor
|
||||
key: v1-dependencies-{{ checksum "composer.lock" }}
|
||||
- run: cp .env.testing .env
|
||||
- run: php artisan key:random
|
||||
- run: php artisan key:generate
|
||||
- run: php artisan salt:random
|
||||
- persist_to_workspace:
|
||||
root: ~/repo
|
||||
|
@ -19,9 +19,7 @@ class BsInstallCommand extends Command
|
||||
return;
|
||||
}
|
||||
|
||||
if (config('app.env') != 'testing') {
|
||||
$this->call('key:random');
|
||||
}
|
||||
$this->call('key:generate');
|
||||
$this->call('salt:random');
|
||||
$this->call('migrate', ['--force' => true]);
|
||||
$this->call('jwt:secret', ['--no-interaction' => true]);
|
||||
|
@ -1,74 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class KeyRandomCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'key:random {--show : Display the key instead of modifying files}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Set the application key';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$key = $this->generateRandomKey();
|
||||
|
||||
if ($this->option('show')) {
|
||||
return $this->line('<comment>'.$key.'</comment>');
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
$this->laravel['config']['app.key'] = $key;
|
||||
|
||||
$this->info("Application key [$key] set successfully.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the application key in the environment file.
|
||||
*
|
||||
* @param string $key
|
||||
* @return void
|
||||
*/
|
||||
protected function setKeyInEnvironmentFile($key)
|
||||
{
|
||||
// Unlike Illuminate\Foundation\Console\KeyGenerateCommand,
|
||||
// I add some spaces to the replace pattern.
|
||||
file_put_contents($this->laravel->environmentFilePath(), str_replace(
|
||||
'APP_KEY = '.$this->laravel['config']['app.key'],
|
||||
'APP_KEY = '.$key,
|
||||
file_get_contents($this->laravel->environmentFilePath())
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a random key for the application.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function generateRandomKey()
|
||||
{
|
||||
return 'base64:'.base64_encode(random_bytes(
|
||||
$this->laravel['config']['app.cipher'] == 'AES-128-CBC' ? 16 : 32
|
||||
));
|
||||
}
|
||||
}
|
@ -13,7 +13,6 @@ class Kernel extends ConsoleKernel
|
||||
*/
|
||||
protected $commands = [
|
||||
\Laravel\Passport\Console\KeysCommand::class,
|
||||
Commands\KeyRandomCommand::class,
|
||||
Commands\SaltRandomCommand::class,
|
||||
Commands\BsInstallCommand::class,
|
||||
Commands\PluginEnableCommand::class,
|
||||
|
@ -138,7 +138,7 @@ class SetupController extends Controller
|
||||
]);
|
||||
|
||||
if ($request->has('generate_random')) {
|
||||
Artisan::call('key:random');
|
||||
Artisan::call('key:generate');
|
||||
Artisan::call('salt:random');
|
||||
}
|
||||
Artisan::call('jwt:secret', ['--no-interaction' => true]);
|
||||
|
@ -114,7 +114,7 @@ return [
|
||||
|
|
||||
*/
|
||||
|
||||
'key' => env('APP_KEY', 'base64:MfnScX0W/ViN8bZtRt0P481rWP3igcOK80QstjbXUxI='),
|
||||
'key' => env('APP_KEY'),
|
||||
|
||||
'cipher' => 'AES-256-CBC',
|
||||
|
||||
|
@ -160,7 +160,7 @@ class SetupControllerTest extends TestCase
|
||||
|
||||
// Regenerate keys
|
||||
Artisan::shouldReceive('call')
|
||||
->with('key:random')
|
||||
->with('key:generate')
|
||||
->once()
|
||||
->andReturn(true);
|
||||
Artisan::shouldReceive('call')
|
||||
|
Loading…
Reference in New Issue
Block a user