mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-17 04:32:15 +01:00
Change default generate key env to single line
This commit is contained in:
committed by
Constantin Graf
parent
86d625b18a
commit
0c1f06face
@@ -18,6 +18,7 @@ class SelfHostGenerateKeysCommand extends Command
|
|||||||
*/
|
*/
|
||||||
protected $signature = 'self-host:generate-keys
|
protected $signature = 'self-host:generate-keys
|
||||||
{ --length=4096 : The length of the passport private key }
|
{ --length=4096 : The length of the passport private key }
|
||||||
|
{ --multi-line : Whether to output the keys in multiple lines }
|
||||||
{ --format=env : The format of the output (env, yaml) }';
|
{ --format=env : The format of the output (env, yaml) }';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,6 +35,7 @@ class SelfHostGenerateKeysCommand extends Command
|
|||||||
{
|
{
|
||||||
$format = $this->option('format');
|
$format = $this->option('format');
|
||||||
$key = RSA::createKey((int) $this->option('length'));
|
$key = RSA::createKey((int) $this->option('length'));
|
||||||
|
$multiLine = (bool) $this->option('multi-line');
|
||||||
|
|
||||||
$publicKey = (string) $key->getPublicKey();
|
$publicKey = (string) $key->getPublicKey();
|
||||||
$privateKey = (string) $key;
|
$privateKey = (string) $key;
|
||||||
@@ -41,12 +43,17 @@ class SelfHostGenerateKeysCommand extends Command
|
|||||||
|
|
||||||
if ($format === 'env') {
|
if ($format === 'env') {
|
||||||
$this->line('APP_KEY="'.$appKey.'"');
|
$this->line('APP_KEY="'.$appKey.'"');
|
||||||
$this->line('PASSPORT_PRIVATE_KEY="'.$privateKey.'"');
|
if ($multiLine) {
|
||||||
$this->line('PASSPORT_PUBLIC_KEY="'.$publicKey.'"');
|
$this->line('PASSPORT_PRIVATE_KEY="'.Str::replace("\r\n", "\n", $privateKey).'"');
|
||||||
|
$this->line('PASSPORT_PUBLIC_KEY="'.Str::replace("\r\n", "\n", $publicKey).'"');
|
||||||
|
} else {
|
||||||
|
$this->line('PASSPORT_PRIVATE_KEY="'.Str::replace("\r\n", '\n', $privateKey).'"');
|
||||||
|
$this->line('PASSPORT_PUBLIC_KEY="'.Str::replace("\r\n", '\n', $publicKey).'"');
|
||||||
|
}
|
||||||
} elseif ($format === 'yaml') {
|
} elseif ($format === 'yaml') {
|
||||||
$this->line('APP_KEY: "'.$appKey.'"');
|
$this->line('APP_KEY: "'.$appKey.'"');
|
||||||
$this->line("PASSPORT_PRIVATE_KEY: |\n ".Str::replace("\n", "\n ", $privateKey));
|
$this->line("PASSPORT_PRIVATE_KEY: |\n ".Str::replace("\r\n", "\n ", $privateKey));
|
||||||
$this->line("PASSPORT_PUBLIC_KEY: |\n ".Str::replace("\n", "\n ", $publicKey));
|
$this->line("PASSPORT_PUBLIC_KEY: |\n ".Str::replace("\r\n", "\n ", $publicKey));
|
||||||
} else {
|
} else {
|
||||||
$this->error('Invalid format');
|
$this->error('Invalid format');
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,23 @@ class SelfHostGenerateKeysCommandTest extends TestCase
|
|||||||
$this->assertSame(Command::SUCCESS, $exitCode);
|
$this->assertSame(Command::SUCCESS, $exitCode);
|
||||||
$output = Artisan::output();
|
$output = Artisan::output();
|
||||||
$this->assertStringContainsString('APP_KEY="base64:', $output);
|
$this->assertStringContainsString('APP_KEY="base64:', $output);
|
||||||
$this->assertStringContainsString('PASSPORT_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----', $output);
|
$this->assertStringContainsString('PASSPORT_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n', $output);
|
||||||
$this->assertStringContainsString('PASSPORT_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----', $output);
|
$this->assertStringContainsString('PASSPORT_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----\n', $output);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_generates_app_key_and_passport_keys_in_env_format_in_multiline_if_requested(): void
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
|
||||||
|
// Act
|
||||||
|
$exitCode = $this->withoutMockingConsoleOutput()->artisan('self-host:generate-keys --multi-line');
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
$this->assertSame(Command::SUCCESS, $exitCode);
|
||||||
|
$output = Artisan::output();
|
||||||
|
$this->assertStringContainsString('APP_KEY="base64:', $output);
|
||||||
|
$this->assertStringContainsString("PASSPORT_PRIVATE_KEY=\"-----BEGIN PRIVATE KEY-----\n", $output);
|
||||||
|
$this->assertStringContainsString("PASSPORT_PUBLIC_KEY=\"-----BEGIN PUBLIC KEY-----\n", $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_generates_app_key_and_passport_keys_in_yaml_format_if_requested(): void
|
public function test_generates_app_key_and_passport_keys_in_yaml_format_if_requested(): void
|
||||||
|
|||||||
Reference in New Issue
Block a user