-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor command names + add key commands
Signed-off-by: Dieter Coopman <dieter@deltasolutions.be>
- Loading branch information
1 parent
939d76b
commit 2d37c3d
Showing
12 changed files
with
203 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Dietercoopman\SajanPhp; | ||
|
||
use Dietercoopman\SajanPhp\Services\Configurator; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Process\Process; | ||
use function Termwind\render; | ||
|
||
class KeyCopyCommand extends BaseCommand | ||
{ | ||
/** | ||
* Configure the command. | ||
* | ||
* @return void | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('key:copy') | ||
->setDescription('Copy the value of a public key to your clipboard') | ||
->setAliases(['kc']); | ||
} | ||
|
||
/** | ||
* Execute the command. | ||
* | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @return int | ||
*/ | ||
public function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$helper = $this->getHelper('question'); | ||
$configurator = (new Configurator()); | ||
|
||
$this->title(); | ||
$keyfile = '~/.ssh/' . $configurator->askFor($helper, $input, $output, $this->getPossibleSshKeys(), 'Please select the ssh key you want to use'); | ||
Process::fromShellCommandline('cat '.$keyfile.'.pub | pbcopy')->mustRun()->getOutput(); | ||
render('<span class="success mt-1 mb-1">The public key '.$keyfile.' has been copied to your clipboard.</span>'); | ||
|
||
return 0; | ||
} | ||
|
||
private function getPossibleSshKeys(): array | ||
{ | ||
$possibleKeys = Process::fromShellCommandline('ls ~/.ssh')->mustRun()->getOutput(); | ||
$possibleKeys = collect(explode("\n", $possibleKeys))->filter(function ($key) { | ||
return strstr($key, '.pub'); | ||
})->transform(function ($key) { | ||
return str_replace('.pub', '', $key); | ||
})->toArray(); | ||
return array_values($possibleKeys); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Dietercoopman\SajanPhp; | ||
|
||
use Dietercoopman\SajanPhp\Services\Configurator; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Process\Process; | ||
use function Termwind\ask; | ||
use function Termwind\render; | ||
|
||
class KeyMakeCommand extends BaseCommand | ||
{ | ||
/** | ||
* Configure the command. | ||
* | ||
* @return void | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('key:make') | ||
->setDescription('Create a new ssh key') | ||
->setAliases(['km']); | ||
} | ||
|
||
/** | ||
* Execute the command. | ||
* | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @return int | ||
*/ | ||
public function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$passwordsEqual = false; | ||
$this->title(); | ||
|
||
render('<div class="ml-1">Generating public/private rsa key pair.</div>'); | ||
$file = ask('<div class="ml-1 mr-1">Enter file in which to save the key (~/.ssh/id_rsa):</div>'); | ||
while (!$passwordsEqual) { | ||
$passphrase = ask('<div class="ml-1 mr-1">Enter passphrase (empty for no passphrase):</div>', ishidden: true); | ||
$passphrasecheck = ask('<div class="ml-1 mr-1">Enter same passphrase again:</div>', ishidden: true); | ||
$passwordsEqual = $passphrasecheck === $passphrase; | ||
} | ||
|
||
$command = 'ssh-keygen -t rsa -f '.$file.' -q -P "'.$passphrase.'"'; | ||
exec($command); | ||
|
||
render('<div class="ml-1">Your identification has been saved in '.$file .'</div>'); | ||
render('<div class="ml-1">Your public key has been saved in '.$file.'.pub</div>'); | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php namespace Dietercoopman\SajanPhp; | ||
|
||
use Dietercoopman\SajanPhp\Services\Configurator; | ||
use Dietercoopman\SajanPhp\Services\Laravel; | ||
use Dietercoopman\SajanPhp\Services\Server; | ||
use Dietercoopman\SajanPhp\Traits\HasServer; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Question\ChoiceQuestion; | ||
use function Termwind\{render}; | ||
|
||
|
||
class LaravelSitesCommand extends BaseCommand | ||
{ | ||
|
||
use HasServer; | ||
|
||
/** | ||
* Configure the command. | ||
* | ||
* @return void | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('laravel:sites') | ||
->setDescription('Get Laravel applications with their version on a server') | ||
->setAliases(['ls']); | ||
} | ||
|
||
/** | ||
* Execute the command. | ||
* | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @return int | ||
*/ | ||
public function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$this->title(); | ||
|
||
$configurator = (new Configurator()); | ||
$choices = $this->getServers($configurator); | ||
|
||
if (count($choices) > 0) { | ||
$helper = $this->getHelper('question'); | ||
$servername = $configurator->askFor($helper, $input, $output, $choices, 'Please select the server you want to run this command for'); | ||
} else { | ||
render('<div class="m-1">You have no saved servers, you can create one with the \'server:create\' command.</div>'); | ||
return 0; | ||
} | ||
|
||
$config = $configurator->validateServer($servername); | ||
$server = (new Laravel())->init($config); | ||
$server->getLaravelApplications($servername); | ||
|
||
return 0; | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters