Skip to content

Commit 175374b

Browse files
committed
switching to Client
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent e9b35dc commit 175374b

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

lib/private/GlobalScale/Config.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,9 @@
2424
namespace OC\GlobalScale;
2525

2626

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;
3327
use daita\NcSmallPhpTools\Traits\TRequest;
3428
use OCP\GlobalScale\IConfig as IGlobalScaleConfig;
29+
use OCP\Http\Client\IClientService;
3530
use OCP\IConfig;
3631

3732

@@ -41,15 +36,21 @@ class Config implements IGlobalScaleConfig {
4136
use TRequest;
4237

4338

39+
/** @var IClientService */
40+
private $clientService;
41+
4442
/** @var IConfig */
4543
private $config;
4644

45+
4746
/**
4847
* Config constructor.
4948
*
49+
* @param IClientService $clientService
5050
* @param IConfig $config
5151
*/
52-
public function __construct(IConfig $config) {
52+
public function __construct(IClientService $clientService, IConfig $config) {
53+
$this->clientService = $clientService;
5354
$this->config = $config;
5455
}
5556

@@ -192,17 +193,24 @@ public function getGSInstances(): array {
192193
/** @var string $lookup */
193194
$lookup = $this->config->getSystemValue('lookup_server', '');
194195

195-
$request = new Request('/instances', Request::TYPE_GET);
196-
$request->setAddressFromUrl($lookup);
196+
if ($lookup === '') {
197+
return [];
198+
}
199+
200+
$client = $this->clientService->newClient();
201+
$url = rtrim($lookup, '/') . '/instances';
197202

198203
try {
199-
return $instances = $this->retrieveJson($request);
200-
} catch (RequestContentException | RequestNetworkException | RequestResultSizeException | RequestServerException | RequestResultNotJsonException $e) {
204+
$response = $client->get($url, ['connect_timeout' => 10]);
205+
} catch (\Exception $e) {
201206
\OC::$server->getLogger()
202-
->log(2, 'Issue while retrieving instances from lookup: ' . $e->getMessage());
207+
->warning('Issue while retrieving instances from lookup: ' . $e->getMessage());
203208

204209
return [];
205210
}
211+
212+
return json_decode($response->getBody(), true);
206213
}
207214

208215
}
216+

lib/private/Server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ public function __construct($webRoot, \OC\Config $config) {
12321232
});
12331233

12341234
$this->registerService(IConfig::class, function (Server $c) {
1235-
return new GlobalScale\Config($c->getConfig());
1235+
return new GlobalScale\Config($c->getHTTPClientService(), $c->getConfig());
12361236
});
12371237

12381238
$this->registerService(ICloudFederationProviderManager::class, function (Server $c) {

0 commit comments

Comments
 (0)