aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2023-10-12 12:25:16 +0200
committerJoas Schilling <coding@schilljs.com>2023-10-13 08:34:42 +0200
commitb246d51cbc5105b9c4e85867297ee19f6d2459e5 (patch)
treeb0551f9a6b21c5fe776a3c1cd3dee1d3be54757f
parent4dbe0677ad25d9ccbc4efcdc67c0e5b3d736d70f (diff)
downloadnextcloud-server-b246d51cbc5105b9c4e85867297ee19f6d2459e5.tar.gz
nextcloud-server-b246d51cbc5105b9c4e85867297ee19f6d2459e5.zip
fix(OCM): Make the OCM provider stateful so apps can add resources
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r--apps/cloud_federation_api/appinfo/info.xml4
-rw-r--r--apps/cloud_federation_api/lib/Capabilities.php14
-rw-r--r--lib/private/OCM/OCMDiscoveryService.php17
-rw-r--r--lib/private/Server.php4
4 files changed, 21 insertions, 18 deletions
diff --git a/apps/cloud_federation_api/appinfo/info.xml b/apps/cloud_federation_api/appinfo/info.xml
index f9ca8185dcf..8de2444ff2a 100644
--- a/apps/cloud_federation_api/appinfo/info.xml
+++ b/apps/cloud_federation_api/appinfo/info.xml
@@ -12,8 +12,8 @@
<types>
<filesystem/>
</types>
- <category>files</category>
- <bugs>https://github.com/nextcloud/cloud_federation/issues</bugs>
+ <category>integration</category>
+ <bugs>https://github.com/nextcloud/server/issues</bugs>
<dependencies>
<nextcloud min-version="28" max-version="28"/>
</dependencies>
diff --git a/apps/cloud_federation_api/lib/Capabilities.php b/apps/cloud_federation_api/lib/Capabilities.php
index 1682effb145..cd44d13117a 100644
--- a/apps/cloud_federation_api/lib/Capabilities.php
+++ b/apps/cloud_federation_api/lib/Capabilities.php
@@ -28,11 +28,11 @@ declare(strict_types=1);
namespace OCA\CloudFederationAPI;
-use OC\OCM\Model\OCMProvider;
use OC\OCM\Model\OCMResource;
use OCP\Capabilities\ICapability;
use OCP\IURLGenerator;
use OCP\OCM\Exceptions\OCMArgumentException;
+use OCP\OCM\IOCMProvider;
class Capabilities implements ICapability {
@@ -40,6 +40,7 @@ class Capabilities implements ICapability {
public function __construct(
private IURLGenerator $urlGenerator,
+ private IOCMProvider $provider,
) {
}
@@ -63,24 +64,23 @@ class Capabilities implements ICapability {
public function getCapabilities() {
$url = $this->urlGenerator->linkToRouteAbsolute('cloud_federation_api.requesthandlercontroller.addShare');
- $provider = new OCMProvider();
- $provider->setEnabled(true);
- $provider->setApiVersion(self::API_VERSION);
+ $this->provider->setEnabled(true);
+ $this->provider->setApiVersion(self::API_VERSION);
$pos = strrpos($url, '/');
if (false === $pos) {
throw new OCMArgumentException('generated route should contains a slash character');
}
- $provider->setEndPoint(substr($url, 0, $pos));
+ $this->provider->setEndPoint(substr($url, 0, $pos));
$resource = new OCMResource();
$resource->setName('file')
->setShareTypes(['user', 'group'])
->setProtocols(['webdav' => '/public.php/webdav/']);
- $provider->setResourceTypes([$resource]);
+ $this->provider->setResourceTypes([$resource]);
- return ['ocm' => $provider->jsonSerialize()];
+ return ['ocm' => $this->provider->jsonSerialize()];
}
}
diff --git a/lib/private/OCM/OCMDiscoveryService.php b/lib/private/OCM/OCMDiscoveryService.php
index e3b1d350813..ac9bf2a3965 100644
--- a/lib/private/OCM/OCMDiscoveryService.php
+++ b/lib/private/OCM/OCMDiscoveryService.php
@@ -27,7 +27,6 @@ declare(strict_types=1);
namespace OC\OCM;
use JsonException;
-use OC\OCM\Model\OCMProvider;
use OCP\AppFramework\Http;
use OCP\Http\Client\IClientService;
use OCP\ICache;
@@ -54,7 +53,8 @@ class OCMDiscoveryService implements IOCMDiscoveryService {
ICacheFactory $cacheFactory,
private IClientService $clientService,
private IConfig $config,
- private LoggerInterface $logger
+ private IOCMProvider $provider,
+ private LoggerInterface $logger,
) {
$this->cache = $cacheFactory->createDistributed('ocm-discovery');
}
@@ -69,13 +69,12 @@ class OCMDiscoveryService implements IOCMDiscoveryService {
*/
public function discover(string $remote, bool $skipCache = false): IOCMProvider {
$remote = rtrim($remote, '/');
- $provider = new OCMProvider();
if (!$skipCache) {
try {
- $provider->import(json_decode($this->cache->get($remote) ?? '', true, 8, JSON_THROW_ON_ERROR) ?? []);
- if ($this->supportedAPIVersion($provider->getApiVersion())) {
- return $provider; // if cache looks valid, we use it
+ $this->provider->import(json_decode($this->cache->get($remote) ?? '', true, 8, JSON_THROW_ON_ERROR) ?? []);
+ if ($this->supportedAPIVersion($this->provider->getApiVersion())) {
+ return $this->provider; // if cache looks valid, we use it
}
} catch (JsonException|OCMProviderException $e) {
// we ignore cache on issues
@@ -96,7 +95,7 @@ class OCMDiscoveryService implements IOCMDiscoveryService {
if ($response->getStatusCode() === Http::STATUS_OK) {
$body = $response->getBody();
// update provider with data returned by the request
- $provider->import(json_decode($body, true, 8, JSON_THROW_ON_ERROR) ?? []);
+ $this->provider->import(json_decode($body, true, 8, JSON_THROW_ON_ERROR) ?? []);
$this->cache->set($remote, $body, 60 * 60 * 24);
}
} catch (JsonException|OCMProviderException $e) {
@@ -109,11 +108,11 @@ class OCMDiscoveryService implements IOCMDiscoveryService {
throw new OCMProviderException('error while requesting remote ocm provider');
}
- if (!$this->supportedAPIVersion($provider->getApiVersion())) {
+ if (!$this->supportedAPIVersion($this->provider->getApiVersion())) {
throw new OCMProviderException('API version not supported');
}
- return $provider;
+ return $this->provider;
}
/**
diff --git a/lib/private/Server.php b/lib/private/Server.php
index d2a1d890ccd..949a7ccfd3f 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -124,6 +124,7 @@ use OC\Metadata\Capabilities as MetadataCapabilities;
use OC\Metadata\IMetadataManager;
use OC\Metadata\MetadataManager;
use OC\Notification\Manager;
+use OC\OCM\Model\OCMProvider;
use OC\OCM\OCMDiscoveryService;
use OC\OCS\DiscoveryService;
use OC\Preview\GeneratorHelper;
@@ -232,6 +233,7 @@ use OCP\Lockdown\ILockdownManager;
use OCP\Log\ILogFactory;
use OCP\Mail\IMailer;
use OCP\OCM\IOCMDiscoveryService;
+use OCP\OCM\IOCMProvider;
use OCP\Remote\Api\IApiFactory;
use OCP\Remote\IInstanceFactory;
use OCP\RichObjectStrings\IValidator;
@@ -1426,6 +1428,8 @@ class Server extends ServerContainer implements IServerContainer {
$this->registerAlias(IPhoneNumberUtil::class, PhoneNumberUtil::class);
+ $this->registerAlias(IOCMProvider::class, OCMProvider::class);
+
$this->connectDispatcher();
}