From 973d15883f9fc6b16294f37967aa92de938e0c72 Mon Sep 17 00:00:00 2001 From: Joe Dixon Date: Thu, 24 Nov 2022 14:23:15 +0000 Subject: [PATCH 1/4] Add env:passport command --- src/Commands/EnvPassportCommand.php | 68 +++++++++++++++++++++++++++++ vapor | 1 + 2 files changed, 69 insertions(+) create mode 100644 src/Commands/EnvPassportCommand.php diff --git a/src/Commands/EnvPassportCommand.php b/src/Commands/EnvPassportCommand.php new file mode 100644 index 00000000..04facdaa --- /dev/null +++ b/src/Commands/EnvPassportCommand.php @@ -0,0 +1,68 @@ +setName('env:passport') + ->addArgument('environment', InputArgument::OPTIONAL, 'The environment name') + ->setDescription('Store the application\'s Passport keys in the given environment file'); + } + + /** + * Execute the command. + * + * @return void + */ + public function handle() + { + if (! Helpers::confirm('Passport keys are too large to be stored directly as environment variables. You should only use this command if when using encrypted environments. Do you wish to continue?', false)) { + return static::FAILURE; + } + + $environment = $this->argument('environment'); + $environmentFile = '.env.'.$environment; + + if (! file_exists(getcwd().'/'.$environmentFile)) { + Helpers::abort('Unable to find .env file for environment: '.$environment); + } + + if (! file_exists(getcwd().'/storage/oauth-private.key') || + ! file_exists(getcwd().'/storage/oauth-public.key')) { + Helpers::abort('Unable to find Passport keys in [storage] directory.'); + } + + $contents = file_get_contents(getcwd().'/'.$environmentFile); + + try { + $variables = Dotenv::parse($contents); + } catch (ExceptionInterface $e) { + Helpers::abort('Unable to parse environment file: '.$environmentFile); + } + + if (array_key_exists('PASSPORT_PRIVATE_KEY', $variables) || array_key_exists('PASSPORT_PRIVATE_KEY', $variables)) { + Helpers::abort('The environment file already contains Passport keys.'); + } + + $contents .= PHP_EOL.'PASSPORT_PRIVATE_KEY="'.file_get_contents(getcwd().'/storage/oauth-private.key').'"'; + $contents .= PHP_EOL.'PASSPORT_PUBLIC_KEY="'.file_get_contents(getcwd().'/storage/oauth-public.key').'"'; + + file_put_contents(getcwd().'/'.$environmentFile, $contents); + + Helpers::info('Keys successfully added to '.$environmentFile.'.'); + Helpers::line('You should now encrypt the environment file using the "env:encrypt" command before redeploying your application.'); + } +} diff --git a/vapor b/vapor index 0f57e093..c5d8cd33 100755 --- a/vapor +++ b/vapor @@ -161,6 +161,7 @@ $app->add(new Commands\ProjectListCommand); $app->add(new Commands\EnvListCommand); $app->add(new Commands\EnvCommand); $app->add(new Commands\EnvDescribeCommand); +$app->add(new Commands\EnvPassportCommand); $app->add(new Commands\EnvPullCommand); $app->add(new Commands\EnvPushCommand); $app->add(new Commands\EnvCloneCommand); From db61b44558088a123629b22b97d588e4dad39e8a Mon Sep 17 00:00:00 2001 From: Joe Dixon Date: Thu, 24 Nov 2022 14:34:32 +0000 Subject: [PATCH 2/4] Typo --- src/Commands/EnvPassportCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/EnvPassportCommand.php b/src/Commands/EnvPassportCommand.php index 04facdaa..4c2d03cc 100644 --- a/src/Commands/EnvPassportCommand.php +++ b/src/Commands/EnvPassportCommand.php @@ -29,7 +29,7 @@ protected function configure() */ public function handle() { - if (! Helpers::confirm('Passport keys are too large to be stored directly as environment variables. You should only use this command if when using encrypted environments. Do you wish to continue?', false)) { + if (! Helpers::confirm('Passport keys are too large to be stored directly as environment variables. You should only use this command when using encrypted environments. Do you wish to continue?', false)) { return static::FAILURE; } From dd306fbb96fdcbd1a26ff942940019cc03d193b3 Mon Sep 17 00:00:00 2001 From: Joe Dixon Date: Thu, 24 Nov 2022 14:36:16 +0000 Subject: [PATCH 3/4] Formatting --- src/Commands/EnvPassportCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/EnvPassportCommand.php b/src/Commands/EnvPassportCommand.php index 4c2d03cc..bff4ee54 100644 --- a/src/Commands/EnvPassportCommand.php +++ b/src/Commands/EnvPassportCommand.php @@ -29,7 +29,7 @@ protected function configure() */ public function handle() { - if (! Helpers::confirm('Passport keys are too large to be stored directly as environment variables. You should only use this command when using encrypted environments. Do you wish to continue?', false)) { + if (! Helpers::confirm('Passport keys are too large to be stored directly as environment variables. You should only use this command when using encrypted environments. Would you like to proceed?', false)) { return static::FAILURE; } From 90eb5b1fcc248033571d2dafc60cc3ae873d0153 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 28 Nov 2022 08:40:31 -0600 Subject: [PATCH 4/4] Update EnvPassportCommand.php --- src/Commands/EnvPassportCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/EnvPassportCommand.php b/src/Commands/EnvPassportCommand.php index bff4ee54..51088a9d 100644 --- a/src/Commands/EnvPassportCommand.php +++ b/src/Commands/EnvPassportCommand.php @@ -29,7 +29,7 @@ protected function configure() */ public function handle() { - if (! Helpers::confirm('Passport keys are too large to be stored directly as environment variables. You should only use this command when using encrypted environments. Would you like to proceed?', false)) { + if (! Helpers::confirm("Passport keys are too large to be stored as AWS Lambda environment variables. You should only use this command when using Laravel's encrypted environment files. Would you like to proceed?", false)) { return static::FAILURE; }