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 @@ - files - https://github.com/nextcloud/cloud_federation/issues + integration + https://github.com/nextcloud/server/issues 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(); }