-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathTrustedServerService.php
More file actions
47 lines (40 loc) · 1.15 KB
/
TrustedServerService.php
File metadata and controls
47 lines (40 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Circles\Service;
use OCA\Federation\TrustedServers;
use Psr\Log\LoggerInterface;
/**
* @psalm-suppress UndefinedClass
*/
class TrustedServerService {
public function __construct(
private readonly ?TrustedServers $trustedServers,
private readonly LoggerInterface $logger,
) {
}
/**
* @return list<array{id: int, url: string, url_hash: string, shared_secret: ?string, status: int, sync_token: ?string, address: string}>
*/
public function getTrustedServers(): array {
if ($this->trustedServers === null) {
return [];
}
$trustedServers = [];
try {
foreach ($this->trustedServers->getServers() as $server) {
if (($server['status'] ?? 0) === TrustedServers::STATUS_OK &&
str_starts_with($server['url'], 'https://')) {
$server['address'] = substr($server['url'], 8);
$trustedServers[] = $server;
}
}
} catch (\Exception $e) {
$this->logger->warning('Could not get trusted servers', ['exception' => $e]);
}
return $trustedServers;
}
}