Skip to content

Commit 46371dc

Browse files
committed
use deploy config from exapp instead of daemon config
Signed-off-by: Anupam Kumar <[email protected]>
1 parent 02b4486 commit 46371dc

File tree

7 files changed

+20
-57
lines changed

7 files changed

+20
-57
lines changed

lib/Controller/HarpController.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ public function __construct(
4747
}
4848

4949
private function validateHarpSharedKey(string $appId): bool {
50-
// todo: cache
51-
$daemonConfig = $this->daemonConfigService->getDaemonConfigByAppId($appId);
52-
if ($daemonConfig === null) {
53-
$this->logger->error('Daemon config not found for the app', ['appId' => $appId]);
50+
$exApp = $this->exAppService->getExApp($appId);
51+
if ($exApp === null) {
52+
$this->logger->error('ExApp not found', ['appId' => $appId]);
5453
// Protection for guessing installed ExApps list
5554
$this->throttler->registerAttempt(Application::APP_ID, $this->request->getRemoteAddress(), [
5655
'appid' => $appId,
@@ -59,11 +58,11 @@ private function validateHarpSharedKey(string $appId): bool {
5958
}
6059

6160
try {
62-
if (!isset($daemonConfig->getDeployConfig()['haproxy_password'])) {
61+
if (!isset($exApp->getDeployConfig()['haproxy_password'])) {
6362
$this->logger->error('Harp shared key is not set. Invalid daemon config.');
6463
return false;
6564
}
66-
$harpKey = $this->crypto->decrypt($daemonConfig->getDeployConfig()['haproxy_password']);
65+
$harpKey = $this->crypto->decrypt($exApp->getDeployConfig()['haproxy_password']);
6766
} catch (\Exception $e) {
6867
$this->logger->error('Failed to decrypt harp shared key. Invalid daemon config.', ['exception' => $e]);
6968
return false;

lib/Db/DaemonConfigMapper.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,4 @@ public function findByName(string $name): DaemonConfig {
5454
);
5555
return $this->findEntity($qb);
5656
}
57-
58-
/**
59-
* @param string $appId
60-
*
61-
* @throws DoesNotExistException
62-
* @throws Exception
63-
* @throws MultipleObjectsReturnedException
64-
*
65-
* @return DaemonConfig
66-
*/
67-
public function findByAppId(string $appId): DaemonConfig {
68-
$qb = $this->db->getQueryBuilder();
69-
$qb->select('d.*')
70-
->from('ex_apps', 'a')
71-
->where($qb->expr()->eq('a.appid', $qb->createNamedParameter($appId)))
72-
->leftJoin('a', $this->tableName, 'd', $qb->expr()->eq('a.daemon_config_name', 'd.name'))
73-
->setMaxResults(1);
74-
return $this->findEntity($qb);
75-
}
7657
}

lib/DeployActions/DockerActions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ private function installParsedCertificates(string $dockerUrl, string $containerI
175175
}
176176

177177
private function installFRPCertificates(DaemonConfig $daemonConfig, string $dockerUrl, string $containerId, string $targetDir): void {
178-
if (!HarpService::isHarp($daemonConfig)) {
178+
if (!HarpService::isHarp($daemonConfig->getDeployConfig())) {
179179
return;
180180
}
181181
$certificates = $this->harpService->getFrpCertificates($daemonConfig);

lib/Service/AppAPICommonService.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,8 @@ public function buildAppAPIAuthHeaders(?IRequest $request, ?string $userId, ExAp
3434
'AA-REQUEST-ID' => $request instanceof IRequest ? $request->getId() : 'CLI',
3535
];
3636

37-
// todo: cache
38-
$daemonConfig = $this->daemonConfigService->getDaemonConfigByAppId($exApp->getAppid());
39-
if ($daemonConfig === null) {
40-
// this should not happen
41-
$this->logger->error(sprintf('Daemon config with name %s not found.', $exApp->getDaemonConfigName()));
42-
return $headers;
43-
}
44-
if ($this->harpService->isHarp($daemonConfig)) {
45-
$harpKey = $this->harpService->getHarpSharedKey($daemonConfig);
37+
if ($this->harpService->isHarp($exApp->getDeployConfig())) {
38+
$harpKey = $this->harpService->getHarpSharedKey($exApp->getDeployConfig());
4639
$headers['HARP-SHARED-KEY'] = $harpKey;
4740
$headers['EX-APP-PORT'] = $exApp->getPort();
4841
}

lib/Service/AppAPIService.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -502,14 +502,13 @@ public function heartbeatExApp(
502502
}
503503
$this->logger->info(sprintf('Performing heartbeat on: %s', $exAppUrl . '/heartbeat'));
504504

505-
// todo: cache
506-
$daemonConfig = $this->daemonConfigService->getDaemonConfigByAppId($appId);
507-
if (boolval($daemonConfig->getDeployConfig()['harp'] ?? false)) {
505+
$exApp = $this->exAppService->getExApp($appId);
506+
if ($exApp === null) {
507+
$this->logger->error(sprintf('ExApp with appId %s not found.', $appId));
508+
return false;
509+
}
510+
if (boolval($exApp->getDeployConfig()['harp'] ?? false)) {
508511
$exApp = $this->exAppService->getExApp($appId);
509-
if ($exApp === null) {
510-
$this->logger->error(sprintf('ExApp with appId %s not found.', $appId));
511-
return false;
512-
}
513512
$options['headers'] = array_merge(
514513
$options['headers'],
515514
$this->commonService->buildAppAPIAuthHeaders(null, null, $exApp),

lib/Service/DaemonConfigService.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,4 @@ public function updateDaemonConfig(DaemonConfig $daemonConfig): ?DaemonConfig {
129129
return null;
130130
}
131131
}
132-
133-
public function getDaemonConfigByAppId(string $appId): ?DaemonConfig {
134-
try {
135-
return $this->mapper->findByAppId($appId);
136-
} catch (DoesNotExistException|MultipleObjectsReturnedException|Exception $e) {
137-
$this->logger->debug('Failed to get daemon config by appId. Error: ' . $e->getMessage(), ['exception' => $e]);
138-
return null;
139-
}
140-
}
141132
}

lib/Service/HarpService.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ protected function setupCerts(array $guzzleParams): array {
4747
* @return string|null
4848
* @throws \Exception
4949
*/
50-
public function getHarpSharedKey(DaemonConfig $daemonConfig): ?string {
50+
public function getHarpSharedKey(array $deployConfig): ?string {
5151
try {
52-
return $this->crypto->decrypt($daemonConfig->getDeployConfig()['haproxy_password']);
52+
return $this->crypto->decrypt($deployConfig['haproxy_password']);
5353
} catch (\Exception $e) {
5454
throw new \Exception('Failed to decrypt harp shared key', 0, $e);
5555
}
@@ -84,8 +84,8 @@ protected function buildHarpUrl(DaemonConfig $daemonConfig, string $path): strin
8484
. ltrim($path, '/');
8585
}
8686

87-
public static function isHarp(DaemonConfig $daemonConfig): bool {
88-
return boolval($daemonConfig->getDeployConfig()['harp'] ?? false);
87+
public static function isHarp(array $deployConfig): bool {
88+
return boolval($deployConfig['harp'] ?? false);
8989
}
9090

9191
public static function getHarpExApp(ExApp $exApp): array {
@@ -108,7 +108,7 @@ public static function getHarpExApp(ExApp $exApp): array {
108108
}
109109

110110
public function harpExAppUpdate(DaemonConfig $daemonConfig, ExApp $exApp, bool $added): void {
111-
if (!self::isHarp($daemonConfig)) {
111+
if (!self::isHarp($daemonConfig->getDeployConfig())) {
112112
return;
113113
}
114114
$this->initGuzzleClient($daemonConfig);
@@ -141,7 +141,7 @@ public function harpExAppUpdate(DaemonConfig $daemonConfig, ExApp $exApp, bool $
141141
* @return array{tls_enabled: bool, ca_crt: string, client_crt: string, client_key: string}|null
142142
*/
143143
public function getFrpCertificates(DaemonConfig $daemonConfig): ?array {
144-
if (!self::isHarp($daemonConfig)) {
144+
if (!self::isHarp($daemonConfig->getDeployConfig())) {
145145
return null;
146146
}
147147
$this->initGuzzleClient($daemonConfig);

0 commit comments

Comments
 (0)