Skip to content

Commit a2a0e63

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

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

lib/private/GlobalScale/Config.php

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,29 @@
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;
33-
use daita\NcSmallPhpTools\Traits\TRequest;
3427
use OCP\GlobalScale\IConfig as IGlobalScaleConfig;
28+
use OCP\Http\Client\IClientService;
3529
use OCP\IConfig;
3630

3731

3832
class Config implements IGlobalScaleConfig {
3933

4034

41-
use TRequest;
42-
35+
/** @var IClientService */
36+
private $clientService;
4337

4438
/** @var IConfig */
4539
private $config;
4640

41+
4742
/**
4843
* Config constructor.
4944
*
45+
* @param IClientService $clientService
5046
* @param IConfig $config
5147
*/
52-
public function __construct(IConfig $config) {
48+
public function __construct(IClientService $clientService, IConfig $config) {
49+
$this->clientService = $clientService;
5350
$this->config = $config;
5451
}
5552

@@ -192,17 +189,24 @@ public function getGSInstances(): array {
192189
/** @var string $lookup */
193190
$lookup = $this->config->getSystemValue('lookup_server', '');
194191

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';
197198

198199
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) {
201202
\OC::$server->getLogger()
202-
->log(2, 'Issue while retrieving instances from lookup: ' . $e->getMessage());
203+
->warning('Issue while retrieving instances from lookup: ' . $e->getMessage());
203204

204205
return [];
205206
}
207+
208+
return json_decode($response->getBody(), true);
206209
}
207210

208211
}
212+

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)