Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 47 additions & 19 deletions lib/Command/Daemon/ListDaemons.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class ListDaemons extends Command {
Expand All @@ -30,6 +31,7 @@ public function __construct(
protected function configure(): void {
$this->setName('app_api:daemon:list');
$this->setDescription('List registered daemons');
$this->addOption('show-deploy-config', null, InputOption::VALUE_NONE, 'Show full deploy configuration');
}

protected function execute(InputInterface $input, OutputInterface $output): int {
Expand All @@ -42,26 +44,52 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$defaultDaemonName = $this->appConfig->getValueString(Application::APP_ID, 'default_daemon_config', lazy: true);

$output->writeln('Registered ExApp daemon configs:');
$table = new Table($output);
$table->setHeaders(['Def', 'Name', 'Display name', 'Deploy ID', 'Protocol', 'Host', 'NC Url', 'Is HaRP', 'HaRP FRP Address', 'HaRP Docker Socket Port']);
$rows = [];

foreach ($daemonConfigs as $daemon) {
$rows[] = [
$daemon->getName() === $defaultDaemonName ? '*' : '',
$daemon->getName(), $daemon->getDisplayName(),
$daemon->getAcceptsDeployId(),
$daemon->getProtocol(),
$daemon->getHost(),
$daemon->getDeployConfig()['nextcloud_url'],
isset($daemon->getDeployConfig()['harp']) ? 'yes' : 'no',
$daemon->getDeployConfig()['harp']['frp_address'] ?? '(none)',
$daemon->getDeployConfig()['harp']['docker_socket_port'] ?? '(none)',
];
}

$table->setRows($rows);
$table->render();
if ($input->getOption('show-deploy-config')) {
foreach ($daemonConfigs as $daemon) {
$deployConfig = $daemon->getDeployConfig();

if (isset($deployConfig['haproxy_password'])) {
$deployConfig['haproxy_password'] = '***';
}

$daemonInfo = [
'name' => $daemon->getName(),
'display_name' => $daemon->getDisplayName(),
'deploy_id' => $daemon->getAcceptsDeployId(),
'protocol' => $daemon->getProtocol(),
'host' => $daemon->getHost(),
'deploy_config' => $deployConfig,
];

$output->writeln(json_encode($daemonInfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
$output->writeln('');
}
} else {
$table = new Table($output);
$headers = ['Def', 'Name', 'Display name', 'Deploy ID', 'Protocol', 'Host', 'NC Url', 'Is HaRP', 'HaRP FRP Address', 'HaRP Docker Socket Port'];
$table->setHeaders($headers);

$rows = [];
foreach ($daemonConfigs as $daemon) {
$deployConfig = $daemon->getDeployConfig();
$rows[] = [
$daemon->getName() === $defaultDaemonName ? '*' : '',
$daemon->getName(),
$daemon->getDisplayName(),
$daemon->getAcceptsDeployId(),
$daemon->getProtocol(),
$daemon->getHost(),
$deployConfig['nextcloud_url'],
isset($deployConfig['harp']) ? 'yes' : 'no',
$deployConfig['harp']['frp_address'] ?? '(none)',
$deployConfig['harp']['docker_socket_port'] ?? '(none)',
];
}

$table->setRows($rows);
$table->render();
}

return 0;
}
Expand Down