-
Notifications
You must be signed in to change notification settings - Fork 17
#697 Setup check for the HaRP container's version #739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
af1caaf
#697 Setup check for the HaRP container's version
bnw ab12247
#697 Fix psalm errors
7faf02f
Update lib/SetupChecks/HarpVersionCheck.php
bnw d0d5aba
#697 Improve readability.
ac386ae
#697 Fix formatting
49f2905
#697 Make function private if possible
e95d70b
#697 Handle the case where no cache is available
e376765
#697 Fix formatting if there are multiple errors.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,103 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\AppAPI\SetupChecks; | ||
|
|
||
| use OCA\AppAPI\AppInfo\Application; | ||
| use OCA\AppAPI\Db\DaemonConfig; | ||
| use OCA\AppAPI\Service\DaemonConfigService; | ||
| use OCA\AppAPI\Service\HarpService; | ||
| use OCP\ICacheFactory; | ||
| use OCP\IL10N; | ||
| use OCP\SetupCheck\ISetupCheck; | ||
| use OCP\SetupCheck\SetupResult; | ||
| use Psr\Log\LoggerInterface; | ||
|
|
||
| class HarpVersionCheck implements ISetupCheck { | ||
| private ?\OCP\ICache $cache = null; | ||
|
|
||
| public function __construct( | ||
| private readonly IL10N $l10n, | ||
| private readonly LoggerInterface $logger, | ||
| private readonly DaemonConfigService $daemonConfigService, | ||
| private readonly HarpService $harpService, | ||
| ICacheFactory $cacheFactory, | ||
| ) { | ||
| if ($cacheFactory->isAvailable()) { | ||
| $this->cache = $cacheFactory->createDistributed(Application::APP_ID . '/harp_version_check'); | ||
| } | ||
| } | ||
|
|
||
| public function getName(): string { | ||
| return $this->l10n->t('AppAPI HaRP version check'); | ||
| } | ||
|
|
||
| public function getCategory(): string { | ||
| return 'system'; | ||
| } | ||
|
|
||
| /** | ||
| * @return DaemonConfig[] | ||
| */ | ||
| private function getHaRPDaemonConfigs(): array { | ||
| $allDaemons = $this->daemonConfigService->getRegisteredDaemonConfigs(); | ||
| return array_filter($allDaemons, function (DaemonConfig $daemon) { | ||
| return HarpService::isHarp($daemon->getDeployConfig()); | ||
| }); | ||
| } | ||
|
|
||
| public function run(): SetupResult { | ||
| $harpDaemons = $this->getHaRPDaemonConfigs(); | ||
|
|
||
| if (empty($harpDaemons)) { | ||
| return SetupResult::success(); | ||
| } | ||
|
|
||
| $issues = []; | ||
| foreach ($harpDaemons as $daemonConfig) { | ||
| try { | ||
| $versionString = $this->getHarpVersion($daemonConfig); | ||
| if ($versionString === null) { | ||
| $issues[] = $this->l10n->t('Could not retrieve HaRP version from daemon "%s"', [$daemonConfig->getName()]); | ||
| continue; | ||
| } | ||
| if (!$this->fulfillsMinimumVersionRequirement($versionString)) { | ||
| $issues[] = $this->l10n->t('HaRP version for daemon "%s" is "%s", which is too old. The minimum required version is "%s". Please update the daemon to the latest version.', [$daemonConfig->getName(), $versionString, Application::MINIMUM_HARP_VERSION]); | ||
| } | ||
| } catch (\Exception $e) { | ||
| $this->logger->error('Failed to check HaRP version for daemon ' . $daemonConfig->getName() . ': ' . $e->getMessage(), ['exception' => $e]); | ||
| $issues[] = $this->l10n->t('Failed to check HaRP version for daemon "%s": %s', [$daemonConfig->getName(), $e->getMessage()]); | ||
| } | ||
| } | ||
|
|
||
| if (!empty($issues)) { | ||
| return SetupResult::warning( | ||
| implode("<br />", $issues), | ||
| 'https://github.com/nextcloud/HaRP/', | ||
| ); | ||
| } | ||
|
|
||
| return SetupResult::success(); | ||
| } | ||
|
|
||
| private function fulfillsMinimumVersionRequirement(string $version): bool { | ||
| return version_compare($version, Application::MINIMUM_HARP_VERSION, '>='); | ||
| } | ||
|
|
||
| private function getHarpVersion(DaemonConfig $daemonConfig): ?string { | ||
| $cacheKey = $daemonConfig->getName() . '_' . (string)crc32(json_encode($daemonConfig)); | ||
| $version = $this->cache?->get($cacheKey); | ||
| if ($version === null) { | ||
| $version = $this->harpService->getHarpVersion($daemonConfig); | ||
| $oneWeek = 60 * 60 * 24 * 7; | ||
| $this->cache?->set($cacheKey, $version, $oneWeek); | ||
| } | ||
| return $version; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.