Skip to content

Commit c6067d2

Browse files
committed
occ: make daemon commands harp combatible
Signed-off-by: Anupam Kumar <[email protected]>
1 parent ef574df commit c6067d2

File tree

3 files changed

+45
-15
lines changed

3 files changed

+45
-15
lines changed

lib/Command/Daemon/ListDaemons.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4343

4444
$output->writeln('Registered ExApp daemon configs:');
4545
$table = new Table($output);
46-
$table->setHeaders(['Def', 'Name', 'Display name', 'Deploy ID', 'Protocol', 'Host', 'NC Url']);
46+
$table->setHeaders(['Def', 'Name', 'Display name', 'Deploy ID', 'Protocol', 'Host', 'NC Url', 'Is HaRP']);
4747
$rows = [];
4848

4949
foreach ($daemonConfigs as $daemon) {
@@ -53,7 +53,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5353
$daemon->getAcceptsDeployId(),
5454
$daemon->getProtocol(),
5555
$daemon->getHost(),
56-
$daemon->getDeployConfig()['nextcloud_url']
56+
$daemon->getDeployConfig()['nextcloud_url'],
57+
$daemon->getDeployConfig()['harp'] ? 'yes' : 'no',
5758
];
5859
}
5960

lib/Command/Daemon/RegisterDaemon.php

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ protected function configure(): void {
3232
$this->setName('app_api:daemon:register');
3333
$this->setDescription('Register daemon config for ExApp deployment');
3434

35+
// todo: add docs
3536
$this->addArgument('name', InputArgument::REQUIRED);
3637
$this->addArgument('display-name', InputArgument::REQUIRED);
3738
$this->addArgument('accepts-deploy-id', InputArgument::REQUIRED);
@@ -42,13 +43,17 @@ protected function configure(): void {
4243
// daemon-config settings
4344
$this->addOption('net', null, InputOption::VALUE_REQUIRED, 'DeployConfig, the name of the docker network to attach App to');
4445
$this->addOption('haproxy_password', null, InputOption::VALUE_REQUIRED, 'AppAPI Docker Socket Proxy password for HAProxy Basic auth');
45-
4646
$this->addOption('compute_device', null, InputOption::VALUE_REQUIRED, 'Compute device for GPU support (cpu|cuda|rocm)');
47-
4847
$this->addOption('set-default', null, InputOption::VALUE_NONE, 'Set DaemonConfig as default');
49-
50-
$this->addUsage('local_docker "Docker local" "docker-install" "http" "/var/run/docker.sock" "http://nextcloud.local" --net=nextcloud');
51-
$this->addUsage('local_docker "Docker local" "docker-install" "http" "/var/run/docker.sock" "http://nextcloud.local" --net=nextcloud --set-default --compute_device=cuda');
48+
$this->addOption('harp', null, InputOption::VALUE_NONE, 'Set daemon to use HaRP for all docker and exapp communication');
49+
$this->addOption('harp_frp_address', null, InputOption::VALUE_REQUIRED, '[host]:[port] of the HaRP FRP server, default host is same as HaRP host and port is 8782');
50+
$this->addOption('harp_shared_key', null, InputOption::VALUE_REQUIRED, 'HaRP shared key for secure communication between HaRP and AppAPI');
51+
52+
$this->addUsage('manual_install "Manual Install" "manual-install" "http" null "http://nextcloud.local"');
53+
$this->addUsage('local_docker "Docker Local" "docker-install" "http" "/var/run/docker.sock" "http://nextcloud.local" --net=nextcloud');
54+
$this->addUsage('local_docker "Docker Local" "docker-install" "http" "/var/run/docker.sock" "http://nextcloud.local" --net=nextcloud --set-default --compute_device=cuda');
55+
$this->addUsage('docker_install "Docker Socket Proxy" "docker-install" "http" "nextcloud-appapi-dsp:2375" "http://nextcloud.local" --net=nextcloud --set-default --compute_device=cuda');
56+
$this->addUsage('harp_install "Harp Install" "docker-install" "http" "nextcloud-appapi-harp:8780" "http://nextcloud.local" --harp --harp_shared_key "some_very_secure_password" --set-default --compute_device=cuda');
5257
}
5358

5459
protected function execute(InputInterface $input, OutputInterface $output): int {
@@ -58,28 +63,47 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5863
$protocol = $input->getArgument('protocol');
5964
$host = $input->getArgument('host');
6065
$nextcloudUrl = $input->getArgument('nextcloud_url');
61-
62-
$deployConfig = [
63-
'net' => $input->getOption('net') ?? 'host',
64-
'nextcloud_url' => $nextcloudUrl,
65-
'haproxy_password' => $input->getOption('haproxy_password') ?? '',
66-
'computeDevice' => $this->buildComputeDevice($input->getOption('compute_device') ?? 'cpu'),
67-
];
66+
$isHarp = $input->getOption('harp') !== null;
6867

6968
if (($protocol !== 'http') && ($protocol !== 'https')) {
7069
$output->writeln('Value error: The protocol must be `http` or `https`.');
7170
return 1;
7271
}
73-
if (($acceptsDeployId === 'manual-install') && ($protocol !== 'http')) {
72+
if ($acceptsDeployId === 'manual-install' && $protocol !== 'http') {
7473
$output->writeln('Value error: Manual-install daemon supports only `http` protocol.');
7574
return 1;
7675
}
76+
// todo:
77+
if ($acceptsDeployId === 'manual-install' && $isHarp) {
78+
$output->writeln('Value error: Manual-install daemon does not support HaRP.');
79+
return 1;
80+
}
81+
if ($isHarp && !$input->getOption('harp_shared_key')) {
82+
$output->writeln('Value error: HaRP enabled daemon requires `harp_shared_key` option.');
83+
return 1;
84+
}
85+
if ($isHarp && !$input->getOption('harp_frp_address')) {
86+
$output->writeln('Value error: HaRP enabled daemon requires `harp_frp_address` option.');
87+
return 1;
88+
}
7789

7890
if ($this->daemonConfigService->getDaemonConfigByName($name) !== null) {
7991
$output->writeln(sprintf('Skip registration, as daemon config `%s` already registered.', $name));
8092
return 0;
8193
}
8294

95+
$secret = $isHarp
96+
? $input->getOption('harp_shared_key')
97+
: $input->getOption('haproxy_password') ?? '';
98+
99+
$deployConfig = [
100+
'net' => $input->getOption('net') ?? 'host',
101+
'nextcloud_url' => $nextcloudUrl,
102+
'haproxy_password' => $secret,
103+
'computeDevice' => $this->buildComputeDevice($input->getOption('compute_device') ?? 'cpu'),
104+
'harp' => $isHarp,
105+
];
106+
83107
$daemonConfig = $this->daemonConfigService->registerDaemonConfig([
84108
'name' => $name,
85109
'display_name' => $displayName,

lib/Service/DaemonConfigService.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,16 @@ public function __construct(
3333
public function registerDaemonConfig(array $params): ?DaemonConfig {
3434
$bad_patterns = ['http', 'https', 'tcp', 'udp', 'ssh'];
3535
$docker_host = (string)$params['host'];
36+
$frp_host = (string)$params['host'];
3637
foreach ($bad_patterns as $bad_pattern) {
3738
if (str_starts_with($docker_host, $bad_pattern . '://')) {
3839
$this->logger->error('Failed to register daemon configuration. `host` must not include a protocol.');
3940
return null;
4041
}
42+
if (str_starts_with($frp_host, $bad_pattern . '://')) {
43+
$this->logger->error('Failed to register daemon configuration. FRP\'s address must not include a protocol.');
44+
return null;
45+
}
4146
}
4247
if ($params['protocol'] !== 'http' && $params['protocol'] !== 'https') {
4348
$this->logger->error('Failed to register daemon configuration. `protocol` must be `http` or `https`.');

0 commit comments

Comments
 (0)