Skip to content

Commit

Permalink
fix: Allowing generating ssh keys in production
Browse files Browse the repository at this point in the history
  • Loading branch information
lewislarsen committed Aug 10, 2024
1 parent 14b8b26 commit 7a8188e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 25 deletions.
18 changes: 1 addition & 17 deletions app/Console/Commands/GenerateSSHKeyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Command to generate SSH keys for secure communication with remote servers.
*
* This command creates a new SSH key pair for Vanguard, used in remote server operations.
* It includes checks for environment, existing keys, and required configuration.
* It includes checks for existing keys, and required configuration.
*/
class GenerateSSHKeyCommand extends Command
{
Expand All @@ -29,12 +29,6 @@ class GenerateSSHKeyCommand extends Command
*/
public function handle(): void
{
if ($this->appEnvironmentNotAllowed()) {
$this->components->error('Cannot generate SSH keys in a production environment.');

return;
}

if ($this->doSSHKeysAlreadyExist()) {
$this->components->error('SSH keys already exist. Cannot generate new keys.');

Expand Down Expand Up @@ -63,16 +57,6 @@ public function doSSHKeysAlreadyExist(): bool
return file_exists($privateKeyPath) || file_exists($publicKeyPath);
}

/**
* Check if the current environment is production.
*
* @return bool True if the environment is production, false otherwise.
*/
public function appEnvironmentNotAllowed(): bool
{
return app()->environment('production');
}

/**
* Check if the SSH passphrase is missing from the configuration.
*
Expand Down
8 changes: 0 additions & 8 deletions tests/Feature/Console/Commands/GenerateSSHKeyCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@
unlink($publicKeyPath);
});

it('should not generate SSH keys in a production environment', function (): void {
app()->detectEnvironment(fn (): string => 'production'); // Set the environment to production

$this->artisan(GenerateSSHKeyCommand::class)
->expectsOutputToContain('Cannot generate SSH keys in a production environment.')
->assertExitCode(0);
});

it('should generate ssh keys', function (): void {

$pathToSSHKeys = storage_path('app/ssh');
Expand Down

0 comments on commit 7a8188e

Please sign in to comment.