Skip to content

Commit

Permalink
feat(CloudFederationApi): Start implementing 1.1.0 of OCM spec
Browse files Browse the repository at this point in the history
  • Loading branch information
mickenordin committed Aug 13, 2024
1 parent 822aab6 commit 3a78908
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 4 deletions.
9 changes: 7 additions & 2 deletions apps/cloud_federation_api/lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -31,12 +31,16 @@ public function __construct(
* enabled: bool,
* apiVersion: string,
* endPoint: string,
* provider: string,
* resourceTypes: array{
* name: string,
* shareTypes: string[],
* protocols: array<string, string>
* }[],
* },
* },
* capabilities: array{
* string,
* }
* }
* @throws OCMArgumentException
*/
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
40 changes: 39 additions & 1 deletion lib/private/OCM/Model/OCMProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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');
}

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(),
];
}
}
26 changes: 26 additions & 0 deletions lib/public/OCM/IOCMProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
Expand Down

0 comments on commit 3a78908

Please sign in to comment.