|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2017 Robin Appelman <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @license GNU AGPL version 3 or any later version |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
8
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
9
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
10
|
|
|
* License, or (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU Affero General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
19
|
|
|
* |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace OC\Remote\Api; |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
use GuzzleHttp\Exception\ClientException; |
|
26
|
|
|
use OC\ForbiddenException; |
|
27
|
|
|
use OC\Remote\User; |
|
28
|
|
|
use OCP\API; |
|
29
|
|
|
use OCP\Remote\Api\ICapabilitiesApi; |
|
30
|
|
|
use OCP\Remote\Api\IUserApi; |
|
31
|
|
|
|
|
32
|
|
|
class OCS extends ApiBase implements ICapabilitiesApi, IUserApi { |
|
33
|
|
|
/** |
|
34
|
|
|
* @param string $method |
|
35
|
|
|
* @param string $url |
|
36
|
|
|
* @param array $body |
|
37
|
|
|
* @param array $query |
|
38
|
|
|
* @param array $headers |
|
39
|
|
|
* @return array |
|
40
|
|
|
* @throws ForbiddenException |
|
41
|
|
|
* @throws NotFoundException |
|
42
|
|
|
* @throws \Exception |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function request($method, $url, array $body = [], array $query = [], array $headers = []) { |
|
45
|
|
|
try { |
|
46
|
|
|
$response = json_decode(parent::request($method, 'ocs/v2.php/' . $url, $body, $query, $headers), true); |
|
47
|
|
|
} catch (ClientException $e) { |
|
|
|
|
|
|
48
|
|
|
if ($e->getResponse()->getStatusCode() === 404) { |
|
49
|
|
|
throw new NotFoundException(); |
|
50
|
|
|
} else if ($e->getResponse()->getStatusCode() === 403 || $e->getResponse()->getStatusCode() === 401) { |
|
51
|
|
|
throw new ForbiddenException(); |
|
52
|
|
|
} else { |
|
53
|
|
|
throw $e; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
if (!isset($response['ocs']) || !isset($response['ocs']['meta'])) { |
|
57
|
|
|
throw new \Exception('Invalid ocs response'); |
|
58
|
|
|
} |
|
59
|
|
|
if ($response['ocs']['meta']['statuscode'] === API::RESPOND_UNAUTHORISED) { |
|
60
|
|
|
throw new ForbiddenException(); |
|
61
|
|
|
} |
|
62
|
|
|
if ($response['ocs']['meta']['statuscode'] === API::RESPOND_NOT_FOUND) { |
|
63
|
|
|
throw new NotFoundException(); |
|
64
|
|
|
} |
|
65
|
|
|
if ($response['ocs']['meta']['status'] !== 'ok') { |
|
66
|
|
|
throw new \Exception('Unknown ocs error ' . $response['ocs']['meta']['message']); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return $response['ocs']['data']; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param array $data |
|
74
|
|
|
* @param string $type |
|
75
|
|
|
* @param string[] $keys |
|
76
|
|
|
* @throws \Exception |
|
77
|
|
|
*/ |
|
78
|
|
|
private function checkResponseArray(array $data, $type, array $keys) { |
|
79
|
|
|
foreach ($keys as $key) { |
|
80
|
|
|
if (!array_key_exists($key, $data)) { |
|
81
|
|
|
throw new \Exception('Invalid ' . $type . ' response, expected field ' . $key . ' not found'); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function getUser($userId) { |
|
87
|
|
|
$result = $this->request('get', 'cloud/users/' . $userId); |
|
88
|
|
|
$this->checkResponseArray($result, 'user', User::EXPECTED_KEYS); |
|
89
|
|
|
return new User($result); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return array The capabilities in the form of [$appId => [$capability => $value]] |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getCapabilities() { |
|
96
|
|
|
$result = $this->request('get', 'cloud/capabilities'); |
|
97
|
|
|
return $result['capabilities']; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
Scrutinizer analyzes your
composer.json/composer.lockfile if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.