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
27
use daita \NcSmallPhpTools \Traits \TRequest ;
34
28
use OCP \GlobalScale \IConfig as IGlobalScaleConfig ;
29
+ use OCP \Http \Client \IClientService ;
35
30
use OCP \IConfig ;
36
31
37
32
@@ -41,15 +36,21 @@ class Config implements IGlobalScaleConfig {
41
36
use TRequest;
42
37
43
38
39
+ /** @var IClientService */
40
+ private $ clientService ;
41
+
44
42
/** @var IConfig */
45
43
private $ config ;
46
44
45
+
47
46
/**
48
47
* Config constructor.
49
48
*
49
+ * @param IClientService $clientService
50
50
* @param IConfig $config
51
51
*/
52
- public function __construct (IConfig $ config ) {
52
+ public function __construct (IClientService $ clientService , IConfig $ config ) {
53
+ $ this ->clientService = $ clientService ;
53
54
$ this ->config = $ config ;
54
55
}
55
56
@@ -192,17 +193,24 @@ public function getGSInstances(): array {
192
193
/** @var string $lookup */
193
194
$ lookup = $ this ->config ->getSystemValue ('lookup_server ' , '' );
194
195
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 ' ;
197
202
198
203
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 ) {
201
206
\OC ::$ server ->getLogger ()
202
- ->log ( 2 , 'Issue while retrieving instances from lookup: ' . $ e ->getMessage ());
207
+ ->warning ( 'Issue while retrieving instances from lookup: ' . $ e ->getMessage ());
203
208
204
209
return [];
205
210
}
211
+
212
+ return json_decode ($ response ->getBody (), true );
206
213
}
207
214
208
215
}
216
+
0 commit comments