mirror of
https://github.com/nextcloud/server.git
synced 2026-06-09 08:44:07 -04:00
Merge pull request #60953 from nextcloud/carl/IInstanceFactory
chore: Remove unused and long deprecated Remote components
This commit is contained in:
commit
3279c40632
23 changed files with 0 additions and 1086 deletions
|
|
@ -4057,11 +4057,6 @@
|
|||
<code><![CDATA[\RedisCluster::OPT_SLAVE_FAILOVER]]></code>
|
||||
</InvalidArgument>
|
||||
</file>
|
||||
<file src="lib/private/Remote/Api/OCS.php">
|
||||
<ImplementedReturnTypeMismatch>
|
||||
<code><![CDATA[array]]></code>
|
||||
</ImplementedReturnTypeMismatch>
|
||||
</file>
|
||||
<file src="lib/private/Repair/RemoveLinkShares.php">
|
||||
<InvalidPropertyAssignmentValue>
|
||||
<code><![CDATA[$this->userToNotify]]></code>
|
||||
|
|
|
|||
|
|
@ -763,14 +763,6 @@ return array(
|
|||
'OCP\\Profile\\ParameterDoesNotExistException' => $baseDir . '/lib/public/Profile/ParameterDoesNotExistException.php',
|
||||
'OCP\\Profiler\\IProfile' => $baseDir . '/lib/public/Profiler/IProfile.php',
|
||||
'OCP\\Profiler\\IProfiler' => $baseDir . '/lib/public/Profiler/IProfiler.php',
|
||||
'OCP\\Remote\\Api\\IApiCollection' => $baseDir . '/lib/public/Remote/Api/IApiCollection.php',
|
||||
'OCP\\Remote\\Api\\IApiFactory' => $baseDir . '/lib/public/Remote/Api/IApiFactory.php',
|
||||
'OCP\\Remote\\Api\\ICapabilitiesApi' => $baseDir . '/lib/public/Remote/Api/ICapabilitiesApi.php',
|
||||
'OCP\\Remote\\Api\\IUserApi' => $baseDir . '/lib/public/Remote/Api/IUserApi.php',
|
||||
'OCP\\Remote\\ICredentials' => $baseDir . '/lib/public/Remote/ICredentials.php',
|
||||
'OCP\\Remote\\IInstance' => $baseDir . '/lib/public/Remote/IInstance.php',
|
||||
'OCP\\Remote\\IInstanceFactory' => $baseDir . '/lib/public/Remote/IInstanceFactory.php',
|
||||
'OCP\\Remote\\IUser' => $baseDir . '/lib/public/Remote/IUser.php',
|
||||
'OCP\\RichObjectStrings\\Definitions' => $baseDir . '/lib/public/RichObjectStrings/Definitions.php',
|
||||
'OCP\\RichObjectStrings\\IRichTextFormatter' => $baseDir . '/lib/public/RichObjectStrings/IRichTextFormatter.php',
|
||||
'OCP\\RichObjectStrings\\IValidator' => $baseDir . '/lib/public/RichObjectStrings/IValidator.php',
|
||||
|
|
@ -2050,15 +2042,6 @@ return array(
|
|||
'OC\\Profiler\\Profiler' => $baseDir . '/lib/private/Profiler/Profiler.php',
|
||||
'OC\\Profiler\\RoutingDataCollector' => $baseDir . '/lib/private/Profiler/RoutingDataCollector.php',
|
||||
'OC\\RedisFactory' => $baseDir . '/lib/private/RedisFactory.php',
|
||||
'OC\\Remote\\Api\\ApiBase' => $baseDir . '/lib/private/Remote/Api/ApiBase.php',
|
||||
'OC\\Remote\\Api\\ApiCollection' => $baseDir . '/lib/private/Remote/Api/ApiCollection.php',
|
||||
'OC\\Remote\\Api\\ApiFactory' => $baseDir . '/lib/private/Remote/Api/ApiFactory.php',
|
||||
'OC\\Remote\\Api\\NotFoundException' => $baseDir . '/lib/private/Remote/Api/NotFoundException.php',
|
||||
'OC\\Remote\\Api\\OCS' => $baseDir . '/lib/private/Remote/Api/OCS.php',
|
||||
'OC\\Remote\\Credentials' => $baseDir . '/lib/private/Remote/Credentials.php',
|
||||
'OC\\Remote\\Instance' => $baseDir . '/lib/private/Remote/Instance.php',
|
||||
'OC\\Remote\\InstanceFactory' => $baseDir . '/lib/private/Remote/InstanceFactory.php',
|
||||
'OC\\Remote\\User' => $baseDir . '/lib/private/Remote/User.php',
|
||||
'OC\\Repair' => $baseDir . '/lib/private/Repair.php',
|
||||
'OC\\RepairException' => $baseDir . '/lib/private/RepairException.php',
|
||||
'OC\\Repair\\AddBruteForceCleanupJob' => $baseDir . '/lib/private/Repair/AddBruteForceCleanupJob.php',
|
||||
|
|
|
|||
|
|
@ -804,14 +804,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
|
|||
'OCP\\Profile\\ParameterDoesNotExistException' => __DIR__ . '/../../..' . '/lib/public/Profile/ParameterDoesNotExistException.php',
|
||||
'OCP\\Profiler\\IProfile' => __DIR__ . '/../../..' . '/lib/public/Profiler/IProfile.php',
|
||||
'OCP\\Profiler\\IProfiler' => __DIR__ . '/../../..' . '/lib/public/Profiler/IProfiler.php',
|
||||
'OCP\\Remote\\Api\\IApiCollection' => __DIR__ . '/../../..' . '/lib/public/Remote/Api/IApiCollection.php',
|
||||
'OCP\\Remote\\Api\\IApiFactory' => __DIR__ . '/../../..' . '/lib/public/Remote/Api/IApiFactory.php',
|
||||
'OCP\\Remote\\Api\\ICapabilitiesApi' => __DIR__ . '/../../..' . '/lib/public/Remote/Api/ICapabilitiesApi.php',
|
||||
'OCP\\Remote\\Api\\IUserApi' => __DIR__ . '/../../..' . '/lib/public/Remote/Api/IUserApi.php',
|
||||
'OCP\\Remote\\ICredentials' => __DIR__ . '/../../..' . '/lib/public/Remote/ICredentials.php',
|
||||
'OCP\\Remote\\IInstance' => __DIR__ . '/../../..' . '/lib/public/Remote/IInstance.php',
|
||||
'OCP\\Remote\\IInstanceFactory' => __DIR__ . '/../../..' . '/lib/public/Remote/IInstanceFactory.php',
|
||||
'OCP\\Remote\\IUser' => __DIR__ . '/../../..' . '/lib/public/Remote/IUser.php',
|
||||
'OCP\\RichObjectStrings\\Definitions' => __DIR__ . '/../../..' . '/lib/public/RichObjectStrings/Definitions.php',
|
||||
'OCP\\RichObjectStrings\\IRichTextFormatter' => __DIR__ . '/../../..' . '/lib/public/RichObjectStrings/IRichTextFormatter.php',
|
||||
'OCP\\RichObjectStrings\\IValidator' => __DIR__ . '/../../..' . '/lib/public/RichObjectStrings/IValidator.php',
|
||||
|
|
@ -2091,15 +2083,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
|
|||
'OC\\Profiler\\Profiler' => __DIR__ . '/../../..' . '/lib/private/Profiler/Profiler.php',
|
||||
'OC\\Profiler\\RoutingDataCollector' => __DIR__ . '/../../..' . '/lib/private/Profiler/RoutingDataCollector.php',
|
||||
'OC\\RedisFactory' => __DIR__ . '/../../..' . '/lib/private/RedisFactory.php',
|
||||
'OC\\Remote\\Api\\ApiBase' => __DIR__ . '/../../..' . '/lib/private/Remote/Api/ApiBase.php',
|
||||
'OC\\Remote\\Api\\ApiCollection' => __DIR__ . '/../../..' . '/lib/private/Remote/Api/ApiCollection.php',
|
||||
'OC\\Remote\\Api\\ApiFactory' => __DIR__ . '/../../..' . '/lib/private/Remote/Api/ApiFactory.php',
|
||||
'OC\\Remote\\Api\\NotFoundException' => __DIR__ . '/../../..' . '/lib/private/Remote/Api/NotFoundException.php',
|
||||
'OC\\Remote\\Api\\OCS' => __DIR__ . '/../../..' . '/lib/private/Remote/Api/OCS.php',
|
||||
'OC\\Remote\\Credentials' => __DIR__ . '/../../..' . '/lib/private/Remote/Credentials.php',
|
||||
'OC\\Remote\\Instance' => __DIR__ . '/../../..' . '/lib/private/Remote/Instance.php',
|
||||
'OC\\Remote\\InstanceFactory' => __DIR__ . '/../../..' . '/lib/private/Remote/InstanceFactory.php',
|
||||
'OC\\Remote\\User' => __DIR__ . '/../../..' . '/lib/private/Remote/User.php',
|
||||
'OC\\Repair' => __DIR__ . '/../../..' . '/lib/private/Repair.php',
|
||||
'OC\\RepairException' => __DIR__ . '/../../..' . '/lib/private/RepairException.php',
|
||||
'OC\\Repair\\AddBruteForceCleanupJob' => __DIR__ . '/../../..' . '/lib/private/Repair/AddBruteForceCleanupJob.php',
|
||||
|
|
|
|||
|
|
@ -1,77 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OC\Remote\Api;
|
||||
|
||||
use OCP\Http\Client\IClientService;
|
||||
use OCP\Remote\ICredentials;
|
||||
use OCP\Remote\IInstance;
|
||||
|
||||
class ApiBase {
|
||||
public function __construct(
|
||||
private IInstance $instance,
|
||||
private ICredentials $credentials,
|
||||
private IClientService $clientService,
|
||||
) {
|
||||
}
|
||||
|
||||
protected function getHttpClient() {
|
||||
return $this->clientService->newClient();
|
||||
}
|
||||
|
||||
protected function addDefaultHeaders(array $headers) {
|
||||
return array_merge([
|
||||
'OCS-APIREQUEST' => 'true',
|
||||
'Accept' => 'application/json'
|
||||
], $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @param string $url
|
||||
* @param array $body
|
||||
* @param array $query
|
||||
* @param array $headers
|
||||
* @return resource|string
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function request($method, $url, array $body = [], array $query = [], array $headers = []) {
|
||||
$fullUrl = trim($this->instance->getFullUrl(), '/') . '/' . $url;
|
||||
$options = [
|
||||
'query' => $query,
|
||||
'headers' => $this->addDefaultHeaders($headers),
|
||||
'auth' => [$this->credentials->getUsername(), $this->credentials->getPassword()]
|
||||
];
|
||||
if ($body) {
|
||||
$options['body'] = $body;
|
||||
}
|
||||
|
||||
$client = $this->getHttpClient();
|
||||
|
||||
switch ($method) {
|
||||
case 'get':
|
||||
$response = $client->get($fullUrl, $options);
|
||||
break;
|
||||
case 'post':
|
||||
$response = $client->post($fullUrl, $options);
|
||||
break;
|
||||
case 'put':
|
||||
$response = $client->put($fullUrl, $options);
|
||||
break;
|
||||
case 'delete':
|
||||
$response = $client->delete($fullUrl, $options);
|
||||
break;
|
||||
case 'options':
|
||||
$response = $client->options($fullUrl, $options);
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException('Invalid method ' . $method);
|
||||
}
|
||||
|
||||
return $response->getBody();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OC\Remote\Api;
|
||||
|
||||
use OCP\Http\Client\IClientService;
|
||||
use OCP\Remote\Api\IApiCollection;
|
||||
use OCP\Remote\ICredentials;
|
||||
use OCP\Remote\IInstance;
|
||||
|
||||
class ApiCollection implements IApiCollection {
|
||||
public function __construct(
|
||||
private IInstance $instance,
|
||||
private ICredentials $credentials,
|
||||
private IClientService $clientService,
|
||||
) {
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function getCapabilitiesApi() {
|
||||
return new OCS($this->instance, $this->credentials, $this->clientService);
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function getUserApi() {
|
||||
return new OCS($this->instance, $this->credentials, $this->clientService);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OC\Remote\Api;
|
||||
|
||||
use OCP\Http\Client\IClientService;
|
||||
use OCP\Remote\Api\IApiFactory;
|
||||
use OCP\Remote\ICredentials;
|
||||
use OCP\Remote\IInstance;
|
||||
|
||||
class ApiFactory implements IApiFactory {
|
||||
public function __construct(
|
||||
private IClientService $clientService,
|
||||
) {
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function getApiCollection(IInstance $instance, ICredentials $credentials) {
|
||||
return new ApiCollection($instance, $credentials, $this->clientService);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OC\Remote\Api;
|
||||
|
||||
class NotFoundException extends \Exception {
|
||||
}
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OC\Remote\Api;
|
||||
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use OC\ForbiddenException;
|
||||
use OC\Remote\User;
|
||||
use OCP\AppFramework\OCSController;
|
||||
use OCP\Remote\Api\ICapabilitiesApi;
|
||||
use OCP\Remote\Api\IUserApi;
|
||||
|
||||
class OCS extends ApiBase implements ICapabilitiesApi, IUserApi {
|
||||
/**
|
||||
* @param string $method
|
||||
* @param string $url
|
||||
* @param array $body
|
||||
* @param array $query
|
||||
* @param array $headers
|
||||
* @return array
|
||||
* @throws ForbiddenException
|
||||
* @throws NotFoundException
|
||||
* @throws \Exception
|
||||
*/
|
||||
#[\Override]
|
||||
protected function request($method, $url, array $body = [], array $query = [], array $headers = []) {
|
||||
try {
|
||||
$response = json_decode(parent::request($method, 'ocs/v2.php/' . $url, $body, $query, $headers), true);
|
||||
} catch (ClientException $e) {
|
||||
if ($e->getResponse()->getStatusCode() === 404) {
|
||||
throw new NotFoundException();
|
||||
} elseif ($e->getResponse()->getStatusCode() === 403 || $e->getResponse()->getStatusCode() === 401) {
|
||||
throw new ForbiddenException();
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
if (!isset($response['ocs']) || !isset($response['ocs']['meta'])) {
|
||||
throw new \Exception('Invalid ocs response');
|
||||
}
|
||||
if ($response['ocs']['meta']['statuscode'] === OCSController::RESPOND_UNAUTHORISED) {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
if ($response['ocs']['meta']['statuscode'] === OCSController::RESPOND_NOT_FOUND) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
if ($response['ocs']['meta']['status'] !== 'ok') {
|
||||
throw new \Exception('Unknown ocs error ' . $response['ocs']['meta']['message']);
|
||||
}
|
||||
|
||||
return $response['ocs']['data'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param string $type
|
||||
* @param string[] $keys
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function checkResponseArray(array $data, $type, array $keys) {
|
||||
foreach ($keys as $key) {
|
||||
if (!array_key_exists($key, $data)) {
|
||||
throw new \Exception('Invalid ' . $type . ' response, expected field ' . $key . ' not found');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function getUser($userId) {
|
||||
$result = $this->request('get', 'cloud/users/' . $userId);
|
||||
$this->checkResponseArray($result, 'user', User::EXPECTED_KEYS);
|
||||
return new User($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array The capabilities in the form of [$appId => [$capability => $value]]
|
||||
*/
|
||||
#[\Override]
|
||||
public function getCapabilities() {
|
||||
$result = $this->request('get', 'cloud/capabilities');
|
||||
return $result['capabilities'];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OC\Remote;
|
||||
|
||||
use OCP\Remote\ICredentials;
|
||||
|
||||
class Credentials implements ICredentials {
|
||||
public function __construct(
|
||||
private string $user,
|
||||
private string $password,
|
||||
) {
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function getUsername(): string {
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function getPassword(): string {
|
||||
return $this->password;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,107 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OC\Remote;
|
||||
|
||||
use OC\Remote\Api\NotFoundException;
|
||||
use OCP\Http\Client\IClientService;
|
||||
use OCP\ICache;
|
||||
use OCP\Remote\IInstance;
|
||||
use Override;
|
||||
|
||||
/**
|
||||
* Provides some basic info about a remote Nextcloud instance
|
||||
*/
|
||||
class Instance implements IInstance {
|
||||
private string $url;
|
||||
private ?array $status = null;
|
||||
|
||||
public function __construct(
|
||||
string $url,
|
||||
private ICache $cache,
|
||||
private IClientService $clientService,
|
||||
) {
|
||||
$url = str_replace('https://', '', $url);
|
||||
$this->url = str_replace('http://', '', $url);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function getUrl(): string {
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function getFullUrl(): string {
|
||||
return $this->getProtocol() . '://' . $this->getUrl();
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function getVersion(): string {
|
||||
$status = $this->getStatus();
|
||||
return $status['version'];
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function getProtocol(): string {
|
||||
$status = $this->getStatus();
|
||||
return $status['protocol'];
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function isActive(): bool {
|
||||
$status = $this->getStatus();
|
||||
return $status['installed'] && !$status['maintenance'];
|
||||
}
|
||||
|
||||
private function getStatus(): array {
|
||||
if ($this->status) {
|
||||
return $this->status;
|
||||
}
|
||||
$key = 'remote/' . $this->url . '/status';
|
||||
$httpsKey = 'remote/' . $this->url . '/https';
|
||||
$status = $this->cache->get($key);
|
||||
if (!$status) {
|
||||
$response = $this->downloadStatus('https://' . $this->getUrl() . '/status.php');
|
||||
$protocol = 'https';
|
||||
if (!$response) {
|
||||
if ($status = $this->cache->get($httpsKey)) {
|
||||
throw new \Exception('refusing to connect to remote instance(' . $this->url . ') over http that was previously accessible over https');
|
||||
}
|
||||
$response = $this->downloadStatus('http://' . $this->getUrl() . '/status.php');
|
||||
$protocol = 'http';
|
||||
} else {
|
||||
$this->cache->set($httpsKey, true, 60 * 60 * 24 * 365);
|
||||
}
|
||||
$status = json_decode($response, true);
|
||||
if ($status) {
|
||||
$status['protocol'] = $protocol;
|
||||
}
|
||||
if ($status) {
|
||||
$this->cache->set($key, $status, 5 * 60);
|
||||
$this->status = $status;
|
||||
} else {
|
||||
throw new NotFoundException('Remote server not found at address ' . $this->url);
|
||||
}
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
private function downloadStatus(string $url): false|string {
|
||||
try {
|
||||
$request = $this->clientService->newClient()->get($url);
|
||||
$content = $request->getBody();
|
||||
|
||||
// IResponse.getBody responds with null|resource if returning a stream response was requested.
|
||||
// As that's not the case here, we can just ignore the psalm warning by adding an assertion.
|
||||
assert(is_string($content));
|
||||
|
||||
return $content;
|
||||
} catch (\Exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OC\Remote;
|
||||
|
||||
use OCP\Http\Client\IClientService;
|
||||
use OCP\ICache;
|
||||
use OCP\Remote\IInstanceFactory;
|
||||
|
||||
class InstanceFactory implements IInstanceFactory {
|
||||
public function __construct(
|
||||
private ICache $cache,
|
||||
private IClientService $clientService,
|
||||
) {
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function getInstance($url) {
|
||||
return new Instance($url, $this->cache, $this->clientService);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,135 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OC\Remote;
|
||||
|
||||
use OCP\Remote\IUser;
|
||||
|
||||
class User implements IUser {
|
||||
public const EXPECTED_KEYS = [
|
||||
'id',
|
||||
'email',
|
||||
'displayname',
|
||||
'phone',
|
||||
'address',
|
||||
'website',
|
||||
'groups',
|
||||
'language',
|
||||
'quota'
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
private array $data,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
#[\Override]
|
||||
public function getUserId() {
|
||||
return $this->data['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
#[\Override]
|
||||
public function getEmail() {
|
||||
return $this->data['email'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
#[\Override]
|
||||
public function getDisplayName() {
|
||||
return $this->data['displayname'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
#[\Override]
|
||||
public function getPhone() {
|
||||
return $this->data['phone'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
#[\Override]
|
||||
public function getAddress() {
|
||||
return $this->data['address'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
#[\Override]
|
||||
public function getWebsite() {
|
||||
return $this->data['website'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
#[\Override]
|
||||
public function getTwitter() {
|
||||
return $this->data['twitter'] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
#[\Override]
|
||||
public function getGroups() {
|
||||
return $this->data['groups'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
#[\Override]
|
||||
public function getLanguage() {
|
||||
return $this->data['language'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
#[\Override]
|
||||
public function getUsedSpace() {
|
||||
return $this->data['quota']['used'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
#[\Override]
|
||||
public function getFreeSpace() {
|
||||
return $this->data['quota']['free'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
#[\Override]
|
||||
public function getTotalSpace() {
|
||||
return $this->data['quota']['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
#[\Override]
|
||||
public function getQuota() {
|
||||
return $this->data['quota']['quota'];
|
||||
}
|
||||
}
|
||||
|
|
@ -108,8 +108,6 @@ use OC\Preview\Watcher;
|
|||
use OC\Preview\WatcherConnector;
|
||||
use OC\Profile\ProfileManager;
|
||||
use OC\Profiler\Profiler;
|
||||
use OC\Remote\Api\ApiFactory;
|
||||
use OC\Remote\InstanceFactory;
|
||||
use OC\RichObjectStrings\RichTextFormatter;
|
||||
use OC\RichObjectStrings\Validator;
|
||||
use OC\Route\CachingRouter;
|
||||
|
|
@ -254,8 +252,6 @@ use OCP\OCS\IDiscoveryService;
|
|||
use OCP\Preview\IMimeIconProvider;
|
||||
use OCP\Profile\IProfileManager;
|
||||
use OCP\Profiler\IProfiler;
|
||||
use OCP\Remote\Api\IApiFactory;
|
||||
use OCP\Remote\IInstanceFactory;
|
||||
use OCP\RichObjectStrings\IRichTextFormatter;
|
||||
use OCP\RichObjectStrings\IValidator;
|
||||
use OCP\Route\IRouter;
|
||||
|
|
@ -1232,15 +1228,6 @@ class Server extends ServerContainer implements IServerContainer {
|
|||
);
|
||||
});
|
||||
|
||||
$this->registerService(IApiFactory::class, function (ContainerInterface $c) {
|
||||
return new ApiFactory($c->get(IClientService::class));
|
||||
});
|
||||
|
||||
$this->registerService(IInstanceFactory::class, function (ContainerInterface $c) {
|
||||
$memcacheFactory = $c->get(ICacheFactory::class);
|
||||
return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class));
|
||||
});
|
||||
|
||||
$this->registerAlias(IContactsStore::class, ContactsStore::class);
|
||||
$this->registerAlias(IAccountManager::class, AccountManager::class);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCP\Remote\Api;
|
||||
|
||||
/**
|
||||
* Provides access to the various apis of a remote instance
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
interface IApiCollection {
|
||||
/**
|
||||
* @return IUserApi
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
public function getUserApi();
|
||||
|
||||
/**
|
||||
* @return ICapabilitiesApi
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
public function getCapabilitiesApi();
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCP\Remote\Api;
|
||||
|
||||
use OCP\Remote\ICredentials;
|
||||
use OCP\Remote\IInstance;
|
||||
|
||||
/**
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
interface IApiFactory {
|
||||
/**
|
||||
* @param IInstance $instance
|
||||
* @param ICredentials $credentials
|
||||
* @return IApiCollection
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
public function getApiCollection(IInstance $instance, ICredentials $credentials);
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCP\Remote\Api;
|
||||
|
||||
/**
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
interface ICapabilitiesApi {
|
||||
/**
|
||||
* @return array The capabilities in the form of [$appId => [$capability => $value]]
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
public function getCapabilities();
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCP\Remote\Api;
|
||||
|
||||
use OCP\Remote\IUser;
|
||||
|
||||
/**
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
interface IUserApi {
|
||||
/**
|
||||
* @param string $userId
|
||||
* @return IUser
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
public function getUser($userId);
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCP\Remote;
|
||||
|
||||
/**
|
||||
* The credentials for a remote user
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
interface ICredentials {
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
public function getUsername();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
public function getPassword();
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCP\Remote;
|
||||
|
||||
use OCP\AppFramework\Attribute\Consumable;
|
||||
|
||||
/**
|
||||
* Provides some basic info about a remote Nextcloud instance
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
#[Consumable(since: '13.0.0')]
|
||||
interface IInstance {
|
||||
/**
|
||||
* @return string The url of the remote server without protocol
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
public function getUrl(): string;
|
||||
|
||||
/**
|
||||
* @return string The of the remote server with protocol
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
public function getFullUrl(): string;
|
||||
|
||||
/**
|
||||
* @return string The full version string in '13.1.2.3' format
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
public function getVersion(): string;
|
||||
|
||||
/**
|
||||
* @return 'http'|'https'
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
public function getProtocol(): string;
|
||||
|
||||
/**
|
||||
* Check that the remote server is installed and not in maintenance mode
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isActive(): bool;
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCP\Remote;
|
||||
|
||||
/**
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
interface IInstanceFactory {
|
||||
/**
|
||||
* @param string $url
|
||||
* @return IInstance
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
public function getInstance($url);
|
||||
}
|
||||
|
|
@ -1,120 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCP\Remote;
|
||||
|
||||
/**
|
||||
* User info for a remote user
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
interface IUser {
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
public function getUserId();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
public function getEmail();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
public function getDisplayName();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
public function getPhone();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
public function getAddress();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
public function getWebsite();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
public function getTwitter();
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
public function getGroups();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
public function getLanguage();
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
public function getUsedSpace();
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
public function getFreeSpace();
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
public function getTotalSpace();
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*
|
||||
* @since 13.0.0
|
||||
* @deprecated 23.0.0
|
||||
*/
|
||||
public function getQuota();
|
||||
}
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace Test\Remote\Api;
|
||||
|
||||
use OC\ForbiddenException;
|
||||
use OC\Memcache\ArrayCache;
|
||||
use OC\Remote\Api\OCS;
|
||||
use OC\Remote\Credentials;
|
||||
use OC\Remote\InstanceFactory;
|
||||
use OCP\Remote\IInstanceFactory;
|
||||
use Test\TestCase;
|
||||
use Test\Traits\ClientServiceTrait;
|
||||
|
||||
class OCSTest extends TestCase {
|
||||
use ClientServiceTrait;
|
||||
|
||||
/** @var IInstanceFactory */
|
||||
private $instanceFactory;
|
||||
|
||||
#[\Override]
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->instanceFactory = new InstanceFactory(new ArrayCache(), $this->getClientService());
|
||||
$this->expectGetRequest('https://example.com/status.php',
|
||||
'{"installed":true,"maintenance":false,"needsDbUpgrade":false,"version":"13.0.0.5","versionstring":"13.0.0 alpha","edition":"","productname":"Nextcloud"}');
|
||||
}
|
||||
|
||||
protected function getOCSClient() {
|
||||
return new OCS(
|
||||
$this->instanceFactory->getInstance('example.com'),
|
||||
new Credentials('user', 'pass'),
|
||||
$this->getClientService()
|
||||
);
|
||||
}
|
||||
|
||||
protected function getOCSUrl($url) {
|
||||
return 'https://example.com/ocs/v2.php/' . $url;
|
||||
}
|
||||
|
||||
public function testGetUser(): void {
|
||||
$client = $this->getOCSClient();
|
||||
|
||||
$this->expectGetRequest($this->getOCSUrl('cloud/users/user'),
|
||||
'{"ocs":{"meta":{"status":"ok","statuscode":200,"message":"OK"},
|
||||
"data":{"id":"user","quota":{"free":5366379387,"used":2329733,"total":5368709120,"relative":0.040000000000000001,"quota":5368709120},
|
||||
"email":null,"displayname":"test","phone":"","address":"","website":"","twitter":"","groups":["Test","Test1"],"language":"en"}}}');
|
||||
|
||||
$user = $client->getUser('user');
|
||||
$this->assertEquals('user', $user->getUserId());
|
||||
}
|
||||
|
||||
public function testGetUserInvalidResponse(): void {
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Invalid user response, expected field email not found');
|
||||
|
||||
$client = $this->getOCSClient();
|
||||
|
||||
$this->expectGetRequest($this->getOCSUrl('cloud/users/user'),
|
||||
'{"ocs":{"meta":{"status":"ok","statuscode":200,"message":"OK"},
|
||||
"data":{"id":"user"}}}');
|
||||
|
||||
$client->getUser('user');
|
||||
}
|
||||
|
||||
public function testInvalidPassword(): void {
|
||||
$this->expectException(ForbiddenException::class);
|
||||
|
||||
$client = $this->getOCSClient();
|
||||
|
||||
$this->expectGetRequest($this->getOCSUrl('cloud/users/user'),
|
||||
'{"ocs":{"meta":{"status":"failure","statuscode":997,"message":"Current user is not logged in"},"data":[]}}');
|
||||
|
||||
$client->getUser('user');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace Test\Remote;
|
||||
|
||||
use OC\Memcache\ArrayCache;
|
||||
use OC\Remote\Instance;
|
||||
use OCP\ICache;
|
||||
use Test\TestCase;
|
||||
use Test\Traits\ClientServiceTrait;
|
||||
|
||||
class InstanceTest extends TestCase {
|
||||
use ClientServiceTrait;
|
||||
|
||||
/** @var ICache */
|
||||
private $cache;
|
||||
|
||||
#[\Override]
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->cache = new ArrayCache();
|
||||
}
|
||||
|
||||
public function testBasicStatus(): void {
|
||||
$instance = new Instance('example.com', $this->cache, $this->getClientService());
|
||||
$this->expectGetRequest('https://example.com/status.php', '{"installed":true,"maintenance":false,"needsDbUpgrade":false,"version":"13.0.0.5","versionstring":"13.0.0 alpha","edition":"","productname":"Nextcloud"}');
|
||||
|
||||
$this->assertEquals(true, $instance->isActive());
|
||||
$this->assertEquals('13.0.0.5', $instance->getVersion());
|
||||
$this->assertEquals('https', $instance->getProtocol());
|
||||
$this->assertEquals('https://example.com', $instance->getFullUrl());
|
||||
}
|
||||
|
||||
public function testHttpFallback(): void {
|
||||
$instance = new Instance('example.com', $this->cache, $this->getClientService());
|
||||
$this->expectGetRequest('https://example.com/status.php', new \Exception());
|
||||
$this->expectGetRequest('http://example.com/status.php', '{"installed":true,"maintenance":false,"needsDbUpgrade":false,"version":"13.0.0.5","versionstring":"13.0.0 alpha","edition":"","productname":"Nextcloud"}');
|
||||
|
||||
$this->assertEquals('http', $instance->getProtocol());
|
||||
$this->assertEquals('http://example.com', $instance->getFullUrl());
|
||||
}
|
||||
|
||||
public function testRerequestHttps(): void {
|
||||
$instance = new Instance('example.com', $this->cache, $this->getClientService());
|
||||
$this->expectGetRequest('https://example.com/status.php', '{"installed":true,"maintenance":false,"needsDbUpgrade":false,"version":"13.0.0.5","versionstring":"13.0.0 alpha","edition":"","productname":"Nextcloud"}');
|
||||
|
||||
$this->assertEquals('https', $instance->getProtocol());
|
||||
$this->assertEquals(true, $instance->isActive());
|
||||
|
||||
$this->cache->remove('remote/example.com/status');
|
||||
$this->expectGetRequest('https://example.com/status.php', '{"installed":true,"maintenance":true,"needsDbUpgrade":false,"version":"13.0.0.5","versionstring":"13.0.0 alpha","edition":"","productname":"Nextcloud"}');
|
||||
$instance2 = new Instance('example.com', $this->cache, $this->getClientService());
|
||||
$this->assertEquals('https', $instance2->getProtocol());
|
||||
$this->assertEquals(false, $instance2->isActive());
|
||||
}
|
||||
|
||||
public function testPreventDowngradeAttach(): void {
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('refusing to connect to remote instance(example.com) over http that was previously accessible over https');
|
||||
|
||||
$instance = new Instance('example.com', $this->cache, $this->getClientService());
|
||||
$this->expectGetRequest('https://example.com/status.php', '{"installed":true,"maintenance":false,"needsDbUpgrade":false,"version":"13.0.0.5","versionstring":"13.0.0 alpha","edition":"","productname":"Nextcloud"}');
|
||||
|
||||
$this->assertEquals('https', $instance->getProtocol());
|
||||
|
||||
$this->expectGetRequest('https://example.com/status.php', new \Exception());
|
||||
$this->cache->remove('remote/example.com/status');
|
||||
$instance2 = new Instance('example.com', $this->cache, $this->getClientService());
|
||||
$instance2->getProtocol();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue