diff options
Diffstat (limited to 'apps/federation/lib/TrustedServers.php')
-rw-r--r-- | apps/federation/lib/TrustedServers.php | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/apps/federation/lib/TrustedServers.php b/apps/federation/lib/TrustedServers.php index 48cffd2d274..3d15cfac448 100644 --- a/apps/federation/lib/TrustedServers.php +++ b/apps/federation/lib/TrustedServers.php @@ -31,36 +31,19 @@ class TrustedServers { /** remote server revoked access */ public const STATUS_ACCESS_REVOKED = 4; - private DbHandler $dbHandler; - private IClientService $httpClientService; - private LoggerInterface $logger; - private IJobList $jobList; - private ISecureRandom $secureRandom; - private IConfig $config; - private IEventDispatcher $dispatcher; - private ITimeFactory $timeFactory; - /** @var list<array{id: int, url: string, url_hash: string, shared_secret: ?string, status: int, sync_token: ?string}>|null */ private ?array $trustedServersCache = null; public function __construct( - DbHandler $dbHandler, - IClientService $httpClientService, - LoggerInterface $logger, - IJobList $jobList, - ISecureRandom $secureRandom, - IConfig $config, - IEventDispatcher $dispatcher, - ITimeFactory $timeFactory + private DbHandler $dbHandler, + private IClientService $httpClientService, + private LoggerInterface $logger, + private IJobList $jobList, + private ISecureRandom $secureRandom, + private IConfig $config, + private IEventDispatcher $dispatcher, + private ITimeFactory $timeFactory, ) { - $this->dbHandler = $dbHandler; - $this->httpClientService = $httpClientService; - $this->logger = $logger; - $this->jobList = $jobList; - $this->secureRandom = $secureRandom; - $this->config = $config; - $this->dispatcher = $dispatcher; - $this->timeFactory = $timeFactory; } /** @@ -113,9 +96,9 @@ class TrustedServers { * Get all trusted servers * * @return list<array{id: int, url: string, url_hash: string, shared_secret: ?string, status: int, sync_token: ?string}> - * @throws Exception + * @throws \Exception */ - public function getServers() { + public function getServers(): ?array { if ($this->trustedServersCache === null) { $this->trustedServersCache = $this->dbHandler->getAllServer(); } @@ -123,6 +106,26 @@ class TrustedServers { } /** + * Get a trusted server + * + * @return array{id: int, url: string, url_hash: string, shared_secret: ?string, status: int, sync_token: ?string} + * @throws Exception + */ + public function getServer(int $id): ?array { + if ($this->trustedServersCache === null) { + $this->trustedServersCache = $this->dbHandler->getAllServer(); + } + + foreach ($this->trustedServersCache as $server) { + if ($server['id'] === $id) { + return $server; + } + } + + throw new \Exception('No server found with ID: ' . $id); + } + + /** * Check if given server is a trusted Nextcloud server */ public function isTrustedServer(string $url): bool { @@ -155,6 +158,7 @@ class TrustedServers { [ 'timeout' => 3, 'connect_timeout' => 3, + 'verify' => !$this->config->getSystemValue('sharing.federation.allowSelfSignedCertificates', false), ] ); if ($result->getStatusCode() === Http::STATUS_OK) { @@ -166,7 +170,6 @@ class TrustedServers { } } catch (\Exception $e) { $this->logger->error('No Nextcloud server.', [ - 'app' => 'federation', 'exception' => $e, ]); return false; |