-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add setup check to verify whiteboard backend server version and…
… connectivity Signed-off-by: Julius Knorr <[email protected]>
- Loading branch information
1 parent
7a7137f
commit 581775a
Showing
5 changed files
with
135 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Whiteboard\Settings; | ||
|
||
use OCA\Whiteboard\AppInfo\Application; | ||
use OCA\Whiteboard\Service\ConfigService; | ||
use OCP\App\IAppManager; | ||
use OCP\Http\Client\IClientService; | ||
use OCP\IL10N; | ||
use OCP\SetupCheck\SetupResult; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class SetupCheck implements \OCP\SetupCheck\ISetupCheck { | ||
public function __construct( | ||
private IClientService $clientService, | ||
private ConfigService $configService, | ||
private LoggerInterface $logger, | ||
private IL10N $l10n, | ||
private IAppManager $appManager, | ||
) { | ||
} | ||
public function getCategory(): string { | ||
return 'system'; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getName(): string { | ||
return 'Whiteboard server'; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function run(): \OCP\SetupCheck\SetupResult { | ||
$client = $this->clientService->newClient(); | ||
try { | ||
$result = $client->get($this->configService->getCollabBackendUrl()); | ||
} catch (\Exception $e) { | ||
$this->logger->error('Nextcloud server could not connect to whiteboard server', ['exception' => $e]); | ||
return SetupResult::error($this->l10n->t('Nextcloud server could not connect to whiteboard server') . ': ' . $e->getMessage()); | ||
} | ||
|
||
try { | ||
$result = $client->get($this->configService->getCollabBackendUrl() . '/status'); | ||
$resultObject = json_decode((string)$result->getBody(), false, 512, JSON_THROW_ON_ERROR); | ||
$backendVersion = $resultObject?->version ?? null; | ||
if ($backendVersion === null) { | ||
return SetupResult::error($this->l10n->t('No version provided by /status enpdoint')); | ||
} | ||
|
||
$appVersion = $this->appManager->getAppVersion(Application::APP_ID); | ||
if (!version_compare($backendVersion, $appVersion, '==')) { | ||
return SetupResult::warning( | ||
$this->l10n->t('Backend server is running a different version, make sure to upgrade both to the same version. App: %s Backend version: %s', [$appVersion, $backendVersion]) | ||
); | ||
} | ||
|
||
if ($resultObject->connectBack !== true) { | ||
return SetupResult::error( | ||
$this->l10n->t('Whiteboard backend server could not reach Nextcloud: ' . $resultObject->connectBack) | ||
); | ||
} | ||
} catch (\Exception $e) { | ||
$this->logger->error('Failed to connect to whiteboard server status endpoint', ['exception' => $e]); | ||
return SetupResult::error($this->l10n->t('Failed to connect to whiteboard server server status endpoint') . ': ' . $e->getMessage()); | ||
} | ||
|
||
return SetupResult::success($this->l10n->t('Whiteboard server configured properly')); | ||
} | ||
} |
This file contains 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 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