From 3a789084c6c53f3a654ace05cd23b4951f5b686d Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Tue, 13 Aug 2024 15:27:29 +0200 Subject: [PATCH] feat(CloudFederationApi): Start implementing 1.1.0 of OCM spec https://cs3org.github.io/OCM-API/docs.html?branch=v1.1.0&repo=OCM-API&user=cs3org Signed-off-by: Micke Nordin --- .../cloud_federation_api/lib/Capabilities.php | 9 ++++- .../Controller/RequestHandlerController.php | 6 ++- lib/private/OCM/Model/OCMProvider.php | 40 ++++++++++++++++++- lib/public/OCM/IOCMProvider.php | 26 ++++++++++++ 4 files changed, 77 insertions(+), 4 deletions(-) diff --git a/apps/cloud_federation_api/lib/Capabilities.php b/apps/cloud_federation_api/lib/Capabilities.php index 61cc45a24e625..74a778d3c84a0 100644 --- a/apps/cloud_federation_api/lib/Capabilities.php +++ b/apps/cloud_federation_api/lib/Capabilities.php @@ -15,7 +15,7 @@ use OCP\OCM\IOCMProvider; class Capabilities implements ICapability { - public const API_VERSION = '1.0-proposal1'; + public const API_VERSION = '1.1.0'; public function __construct( private IURLGenerator $urlGenerator, @@ -31,12 +31,16 @@ public function __construct( * enabled: bool, * apiVersion: string, * endPoint: string, + * provider: string, * resourceTypes: array{ * name: string, * shareTypes: string[], * protocols: array * }[], - * }, + * }, + * capabilities: array{ + * string, + * } * } * @throws OCMArgumentException */ @@ -45,6 +49,7 @@ public function getCapabilities() { $this->provider->setEnabled(true); $this->provider->setApiVersion(self::API_VERSION); + $this->provider->setCapabilities(['/invite-accepted', '/notifications', '/shares']); $pos = strrpos($url, '/'); if ($pos === false) { diff --git a/apps/cloud_federation_api/lib/Controller/RequestHandlerController.php b/apps/cloud_federation_api/lib/Controller/RequestHandlerController.php index 02b8725afe205..8749b43c67e75 100644 --- a/apps/cloud_federation_api/lib/Controller/RequestHandlerController.php +++ b/apps/cloud_federation_api/lib/Controller/RequestHandlerController.php @@ -7,6 +7,7 @@ use OCA\CloudFederationAPI\Config; use OCA\CloudFederationAPI\ResponseDefinitions; +use OCA\Federation\TrustedServers; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\Attribute\BruteForceProtection; @@ -22,6 +23,7 @@ use OCP\Federation\ICloudFederationFactory; use OCP\Federation\ICloudFederationProviderManager; use OCP\Federation\ICloudIdManager; +use OCP\IConfig; use OCP\IGroupManager; use OCP\IRequest; use OCP\IURLGenerator; @@ -49,8 +51,10 @@ public function __construct( private IURLGenerator $urlGenerator, private ICloudFederationProviderManager $cloudFederationProviderManager, private Config $config, + private IConfig $ocConfig, private ICloudFederationFactory $factory, - private ICloudIdManager $cloudIdManager + private ICloudIdManager $cloudIdManager, + private TrustedServers $trustedServers ) { parent::__construct($appName, $request); } diff --git a/lib/private/OCM/Model/OCMProvider.php b/lib/private/OCM/Model/OCMProvider.php index 17a356428f7a4..adf2e239da908 100644 --- a/lib/private/OCM/Model/OCMProvider.php +++ b/lib/private/OCM/Model/OCMProvider.php @@ -15,13 +15,17 @@ use OCP\OCM\Exceptions\OCMProviderException; use OCP\OCM\IOCMProvider; use OCP\OCM\IOCMResource; +use OCP\IConfig; /** * @since 28.0.0 */ class OCMProvider implements IOCMProvider { + private IConfig $config; + private string $provider; private bool $enabled = false; private string $apiVersion = ''; + private array $capabilities = []; private string $endPoint = ''; /** @var IOCMResource[] */ private array $resourceTypes = []; @@ -30,7 +34,11 @@ class OCMProvider implements IOCMProvider { public function __construct( protected IEventDispatcher $dispatcher, + IConfig $config, + LoggerInterface $logger ) { + $this->config = $config; + $this->provider = 'Nextcloud ' . $config->getSystemValue('version'); } /** @@ -87,6 +95,34 @@ public function getEndPoint(): string { return $this->endPoint; } + /** + * @return string + */ + public function getProvider(): string { + return $this->provider; + } + + /** + * @param array $capabilities + * + * @return this + */ + public function setCapabilities(array $capabilities): static { + foreach ($capabilities as $key => $value) { + if (!in_array($value, $this->capabilities)) { + array_push($this->capabilities, $value); + } + } + + return $this; + } + + /** + * @return array + */ + public function getCapabilities(): array { + return $this->capabilities; + } /** * create a new resource to later add it with {@see IOCMProvider::addResourceType()} * @return IOCMResource @@ -211,7 +247,9 @@ public function jsonSerialize(): array { 'enabled' => $this->isEnabled(), 'apiVersion' => $this->getApiVersion(), 'endPoint' => $this->getEndPoint(), - 'resourceTypes' => $resourceTypes + 'provider' => $this->getProvider(), + 'resourceTypes' => $resourceTypes, + 'capabilities' => $this->getCapabilities(), ]; } } diff --git a/lib/public/OCM/IOCMProvider.php b/lib/public/OCM/IOCMProvider.php index 58b50aca17215..e7c74e9f2461d 100644 --- a/lib/public/OCM/IOCMProvider.php +++ b/lib/public/OCM/IOCMProvider.php @@ -55,6 +55,25 @@ public function setApiVersion(string $apiVersion): static; */ public function getApiVersion(): string; + /** + * returns the capabilities of the API + * + * @return array + * @since 30.0.0 + */ + public function getCapabilities(): array; + + /** + * set the capabilities of the API + * + * @param array $capabilities + * + * @return $this + * @since 30.0.0 + */ + + public function setCapabilities(array $capabilities): static; + /** * configure endpoint * @@ -73,6 +92,13 @@ public function setEndPoint(string $endPoint): static; */ public function getEndPoint(): string; + /** + * get provider + * + * @return string + * @since 30.0.0 + */ + public function getProvider()): string; /** * create a new resource to later add it with {@see addResourceType()} * @return IOCMResource