|
24 | 24 | namespace OC\GlobalScale;
|
25 | 25 |
|
26 | 26 |
|
27 |
| -use daita\NcSmallPhpTools\Exceptions\RequestContentException; |
28 |
| -use daita\NcSmallPhpTools\Exceptions\RequestNetworkException; |
29 |
| -use daita\NcSmallPhpTools\Exceptions\RequestResultNotJsonException; |
30 |
| -use daita\NcSmallPhpTools\Exceptions\RequestResultSizeException; |
31 |
| -use daita\NcSmallPhpTools\Exceptions\RequestServerException; |
32 |
| -use daita\NcSmallPhpTools\Model\Request; |
33 |
| -use daita\NcSmallPhpTools\Traits\TRequest; |
34 | 27 | use OCP\GlobalScale\IConfig as IGlobalScaleConfig;
|
| 28 | +use OCP\Http\Client\IClientService; |
35 | 29 | use OCP\IConfig;
|
36 | 30 |
|
37 | 31 |
|
38 | 32 | class Config implements IGlobalScaleConfig {
|
39 | 33 |
|
40 | 34 |
|
41 |
| - use TRequest; |
42 |
| - |
| 35 | + /** @var IClientService */ |
| 36 | + private $clientService; |
43 | 37 |
|
44 | 38 | /** @var IConfig */
|
45 | 39 | private $config;
|
46 | 40 |
|
| 41 | + |
47 | 42 | /**
|
48 | 43 | * Config constructor.
|
49 | 44 | *
|
| 45 | + * @param IClientService $clientService |
50 | 46 | * @param IConfig $config
|
51 | 47 | */
|
52 |
| - public function __construct(IConfig $config) { |
| 48 | + public function __construct(IClientService $clientService, IConfig $config) { |
| 49 | + $this->clientService = $clientService; |
53 | 50 | $this->config = $config;
|
54 | 51 | }
|
55 | 52 |
|
@@ -192,17 +189,24 @@ public function getGSInstances(): array {
|
192 | 189 | /** @var string $lookup */
|
193 | 190 | $lookup = $this->config->getSystemValue('lookup_server', '');
|
194 | 191 |
|
195 |
| - $request = new Request('/instances', Request::TYPE_GET); |
196 |
| - $request->setAddressFromUrl($lookup); |
| 192 | + if ($lookup === '') { |
| 193 | + return []; |
| 194 | + } |
| 195 | + |
| 196 | + $client = $this->clientService->newClient(); |
| 197 | + $url = rtrim($lookup, '/') . '/instances'; |
197 | 198 |
|
198 | 199 | try {
|
199 |
| - return $instances = $this->retrieveJson($request); |
200 |
| - } catch (RequestContentException | RequestNetworkException | RequestResultSizeException | RequestServerException | RequestResultNotJsonException $e) { |
| 200 | + $response = $client->get($url, ['connect_timeout' => 10]); |
| 201 | + } catch (\Exception $e) { |
201 | 202 | \OC::$server->getLogger()
|
202 |
| - ->log(2, 'Issue while retrieving instances from lookup: ' . $e->getMessage()); |
| 203 | + ->warning('Issue while retrieving instances from lookup: ' . $e->getMessage()); |
203 | 204 |
|
204 | 205 | return [];
|
205 | 206 | }
|
| 207 | + |
| 208 | + return json_decode($response->getBody(), true); |
206 | 209 | }
|
207 | 210 |
|
208 | 211 | }
|
| 212 | + |
0 commit comments