summaryrefslogtreecommitdiff
path: root/src/Command
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2021-04-20 12:45:44 +0200
committerDaniel Weipert <code@drogueronin.de>2021-04-20 12:45:44 +0200
commitf7fc6fd54a5f750de8144b9b05d5ac173470c70a (patch)
tree8796fc49df1d9d80c7b8817a54580c98c2f100f5 /src/Command
parent3983548e7c0f107fa7b7cc3c4c36aa009590b481 (diff)
Adds Connection wrapper for SSH2
Diffstat (limited to 'src/Command')
-rw-r--r--src/Command/RunCommand.php29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/Command/RunCommand.php b/src/Command/RunCommand.php
index 6d8d2c9..cc9c7fd 100644
--- a/src/Command/RunCommand.php
+++ b/src/Command/RunCommand.php
@@ -2,9 +2,8 @@
namespace PHPIAC\Command;
+use PHPIAC\Connection;
use PHPIAC\Task;
-use phpseclib3\Crypt\PublicKeyLoader;
-use phpseclib3\Net\SSH2;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -14,36 +13,38 @@ class RunCommand extends Command
{
protected static $defaultName = 'run';
+ /**
+ * @inheritDoc
+ */
protected function configure()
{
$this->addOption('config', 'c', InputOption::VALUE_REQUIRED, 'Path to config file', getcwd() . '/config.php');
}
+ /**
+ * @inheritDoc
+ */
protected function execute(InputInterface $input, OutputInterface $output): int
{
$config = include $input->getOption('config');
- global $ssh;
- $ssh = new SSH2($config['host']);
- if (! $ssh->login($config['user'], PublicKeyLoader::load(file_get_contents($config['private_key_file'])))) {
- throw new \Exception('Login failed');
- }
+ Connection::getInstance($config['host'], $config['user'], $config['private_key_file']);
- $commands = [];
foreach ($config['tasks'] as $task) {
/**@var Task $task*/
+
if (! $task->module->checkState()) {
- $output->writeln($task->getName() . ': Adding commands from ' . get_class($task->module));
- array_push($commands, ...$task->module->getCommands());
+ $output->writeln($task->getName());
+ $output->writeln('Running');
+
+ $task->module->getCommands();
}
else {
- $output->writeln($task->getName() . ': Skipping commands from ' . get_class($task->module));
+ $output->writeln($task->getName());
+ $output->writeln('Skipping');
}
}
- // run commands in single exec call
- $ssh->exec(implode(PHP_EOL, $commands));
-
return Command::SUCCESS;
}
}