mirror of https://github.com/nextcloud/server.git
ocm controller
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/39574/head
parent
d5fc95b661
commit
8b9e7e235d
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2023 Maxence Lange <maxence@artificial-owl.com>
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OC\Core\Controller;
|
||||
|
||||
use Exception;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\Attribute\IgnoreOpenAPI;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\Http\Response;
|
||||
use OCP\IConfig;
|
||||
use OCP\IRequest;
|
||||
use OCP\Server;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Controller about the endpoint /ocm-provider/
|
||||
*
|
||||
* @since 28.0.0
|
||||
*/
|
||||
class OCMController extends Controller {
|
||||
public function __construct(
|
||||
IRequest $request,
|
||||
private IConfig $config,
|
||||
private LoggerInterface $logger
|
||||
) {
|
||||
parent::__construct('core', $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* generate a OCMProvider with local data and send it as DataResponse.
|
||||
* This replaces the old PHP file ocm-provider/index.php
|
||||
*
|
||||
* @PublicPage
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
#[IgnoreOpenAPI]
|
||||
public function discovery(): Response {
|
||||
try {
|
||||
$cap = Server::get(
|
||||
$this->config->getAppValue(
|
||||
'core',
|
||||
'ocm_providers',
|
||||
'\OCA\CloudFederationAPI\Capabilities'
|
||||
)
|
||||
);
|
||||
|
||||
return new DataResponse(
|
||||
$cap->getCapabilities()['ocm'] ?? ['enabled' => false],
|
||||
Http::STATUS_OK,
|
||||
[
|
||||
'X-NEXTCLOUD-OCM-PROVIDERS' => true,
|
||||
'Content-Type' => 'application/json'
|
||||
]
|
||||
);
|
||||
} catch (ContainerExceptionInterface|Exception $e) {
|
||||
$this->logger->error('issue during OCM discovery request', ['exception' => $e]);
|
||||
|
||||
return new DataResponse(
|
||||
['message' => '/ocm-provider/ not supported'],
|
||||
Http::STATUS_INTERNAL_SERVER_ERROR
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,211 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2023, Maxence Lange <maxence@artificial-owl.com>
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OC\OCM\Model;
|
||||
|
||||
use JsonSerializable;
|
||||
use OCP\OCM\Exceptions\OCMArgumentException;
|
||||
use OCP\OCM\Exceptions\OCMProviderException;
|
||||
use OCP\OCM\IOCMProvider;
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
class OCMProvider implements IOCMProvider, JsonSerializable {
|
||||
private bool $enabled = false;
|
||||
private string $apiVersion = '';
|
||||
private string $endPoint = '';
|
||||
/** @var OCMResource[] */
|
||||
private array $resourceTypes = [];
|
||||
|
||||
/**
|
||||
* @param bool $enabled
|
||||
*
|
||||
* @return OCMProvider
|
||||
*/
|
||||
public function setEnabled(bool $enabled): self {
|
||||
$this->enabled = $enabled;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isEnabled(): bool {
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $apiVersion
|
||||
*
|
||||
* @return OCMProvider
|
||||
*/
|
||||
public function setApiVersion(string $apiVersion): self {
|
||||
$this->apiVersion = $apiVersion;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getApiVersion(): string {
|
||||
return $this->apiVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $endPoint
|
||||
*
|
||||
* @return OCMProvider
|
||||
*/
|
||||
public function setEndPoint(string $endPoint): self {
|
||||
$this->endPoint = $endPoint;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEndPoint(): string {
|
||||
return $this->endPoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OCMResource $resource
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addResourceType(OCMResource $resource): self {
|
||||
$this->resourceTypes[] = $resource;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OCMResource[] $resourceTypes
|
||||
*
|
||||
* @return OCMProvider
|
||||
*/
|
||||
public function setResourceTypes(array $resourceTypes): self {
|
||||
$this->resourceTypes = $resourceTypes;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return OCMResource[]
|
||||
*/
|
||||
public function getResourceTypes(): array {
|
||||
return $this->resourceTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $resourceName
|
||||
* @param string $protocol
|
||||
*
|
||||
* @return string
|
||||
* @throws OCMArgumentException
|
||||
*/
|
||||
public function extractProtocolEntry(string $resourceName, string $protocol): string {
|
||||
foreach ($this->getResourceTypes() as $resource) {
|
||||
if ($resource->getName() === $resourceName) {
|
||||
$entry = $resource->getProtocols()[$protocol] ?? null;
|
||||
if (is_null($entry)) {
|
||||
throw new OCMArgumentException('protocol not found');
|
||||
}
|
||||
|
||||
return (string)$entry;
|
||||
}
|
||||
}
|
||||
|
||||
throw new OCMArgumentException('resource not found');
|
||||
}
|
||||
|
||||
/**
|
||||
* import data from an array
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return self
|
||||
* @throws OCMProviderException in case a descent provider cannot be generated from data
|
||||
* @see self::jsonSerialize()
|
||||
*/
|
||||
public function import(array $data): self {
|
||||
$this->setEnabled(is_bool($data['enabled'] ?? '') ? $data['enabled'] : false)
|
||||
->setApiVersion((string)($data['apiVersion'] ?? ''))
|
||||
->setEndPoint($data['endPoint'] ?? '');
|
||||
|
||||
$resources = [];
|
||||
foreach (($data['resourceTypes'] ?? []) as $resourceData) {
|
||||
$resource = new OCMResource();
|
||||
$resources[] = $resource->import($resourceData);
|
||||
}
|
||||
$this->setResourceTypes($resources);
|
||||
|
||||
if (!$this->looksValid()) {
|
||||
throw new OCMProviderException('remote provider does not look valid');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
private function looksValid(): bool {
|
||||
return ($this->getApiVersion() !== '' && $this->getEndPoint() !== '');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array{
|
||||
* enabled: bool,
|
||||
* apiVersion: string,
|
||||
* endPoint: string,
|
||||
* resourceTypes: array{
|
||||
* name: string,
|
||||
* shareTypes: string[],
|
||||
* protocols: array<string, string>
|
||||
* }[]
|
||||
* }
|
||||
*/
|
||||
public function jsonSerialize(): array {
|
||||
$resourceTypes = []; // this is needed for psalm
|
||||
foreach ($this->getResourceTypes() as $res) {
|
||||
$resourceTypes[] = $res->jsonSerialize();
|
||||
}
|
||||
|
||||
return [
|
||||
'enabled' => $this->isEnabled(),
|
||||
'apiVersion' => $this->getApiVersion(),
|
||||
'endPoint' => $this->getEndPoint(),
|
||||
'resourceTypes' => $resourceTypes
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2023, Maxence Lange <maxence@artificial-owl.com>
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OC\OCM\Model;
|
||||
|
||||
use JsonSerializable;
|
||||
use OCP\OCM\IOCMResource;
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
class OCMResource implements IOCMResource, JsonSerializable {
|
||||
private string $name = '';
|
||||
/** @var string[] */
|
||||
private array $shareTypes = [];
|
||||
/** @var array<string, string> */
|
||||
private array $protocols = [];
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return OCMResource
|
||||
*/
|
||||
public function setName(string $name): self {
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $shareTypes
|
||||
*
|
||||
* @return OCMResource
|
||||
*/
|
||||
public function setShareTypes(array $shareTypes): self {
|
||||
$this->shareTypes = $shareTypes;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getShareTypes(): array {
|
||||
return $this->shareTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string> $protocols
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setProtocols(array $protocols): self {
|
||||
$this->protocols = $protocols;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function getProtocols(): array {
|
||||
return $this->protocols;
|
||||
}
|
||||
|
||||
/**
|
||||
* import data from an array
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return self
|
||||
* @see self::jsonSerialize()
|
||||
*/
|
||||
public function import(array $data): self {
|
||||
return $this->setName((string)($data['name'] ?? ''))
|
||||
->setShareTypes($data['shareTypes'] ?? [])
|
||||
->setProtocols($data['protocols'] ?? []);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array{
|
||||
* name: string,
|
||||
* shareTypes: string[],
|
||||
* protocols: array<string, string>
|
||||
* }
|
||||
*/
|
||||
public function jsonSerialize(): array {
|
||||
return [
|
||||
'name' => $this->getName(),
|
||||
'shareTypes' => $this->getShareTypes(),
|
||||
'protocols' => $this->getProtocols()
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2023, Maxence Lange <maxence@artificial-owl.com>
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OC\OCM;
|
||||
|
||||
use JsonException;
|
||||
use OC\OCM\Model\OCMProvider;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\Http\Client\IClientService;
|
||||
use OCP\ICache;
|
||||
use OCP\ICacheFactory;
|
||||
use OCP\IConfig;
|
||||
use OCP\OCM\Exceptions\OCMProviderException;
|
||||
use OCP\OCM\IOCMDiscoveryService;
|
||||
use OCP\OCM\IOCMProvider;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
class OCMDiscoveryService implements IOCMDiscoveryService {
|
||||
private ICache $cache;
|
||||
private array $supportedAPIVersion =
|
||||
[
|
||||
'1.0-proposal1',
|
||||
'1.0',
|
||||
'1.1'
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
ICacheFactory $cacheFactory,
|
||||
private IClientService $clientService,
|
||||
private IConfig $config,
|
||||
private LoggerInterface $logger
|
||||
) {
|
||||
$this->cache = $cacheFactory->createDistributed('ocm-discovery');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $remote
|
||||
* @param bool $skipCache
|
||||
*
|
||||
* @return IOCMProvider
|
||||
* @throws OCMProviderException
|
||||
*/
|
||||
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
|
||||
}
|
||||
} catch (JsonException|OCMProviderException $e) {
|
||||
// we ignore cache on issues
|
||||
}
|
||||
}
|
||||
|
||||
$client = $this->clientService->newClient();
|
||||
try {
|
||||
$response = $client->get(
|
||||
$remote . '/ocm-provider/',
|
||||
[
|
||||
'timeout' => 10,
|
||||
'verify' => !$this->config->getSystemValueBool('sharing.federation.allowSelfSignedCertificates'),
|
||||
'connect_timeout' => 10,
|
||||
]
|
||||
);
|
||||
|
||||
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->cache->set($remote, $body, 60 * 60 * 24);
|
||||
}
|
||||
} catch (JsonException|OCMProviderException $e) {
|
||||
throw new OCMProviderException('data returned by remote seems invalid - ' . ($body ?? ''));
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->warning('error while discovering ocm provider', [
|
||||
'exception' => $e,
|
||||
'remote' => $remote
|
||||
]);
|
||||
throw new OCMProviderException('error while requesting remote ocm provider');
|
||||
}
|
||||
|
||||
if (!$this->supportedAPIVersion($provider->getApiVersion())) {
|
||||
throw new OCMProviderException('API version not supported');
|
||||
}
|
||||
|
||||
return $provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the version from remote is supported.
|
||||
* The minor version of the API will be ignored:
|
||||
* 1.0.1 is identified as 1.0
|
||||
*
|
||||
* @param string $version
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function supportedAPIVersion(string $version): bool {
|
||||
$dot1 = strpos($version, '.');
|
||||
$dot2 = strpos($version, '.', $dot1 + 1);
|
||||
|
||||
if ($dot2 > 0) {
|
||||
$version = substr($version, 0, $dot2);
|
||||
}
|
||||
|
||||
return (in_array($version, $this->supportedAPIVersion));
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2023, Maxence Lange <maxence@artificial-owl.com>
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
namespace OCP\OCM\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
class OCMArgumentException extends Exception {
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2023, Maxence Lange <maxence@artificial-owl.com>
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
namespace OCP\OCM\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
*/
|
||||
class OCMProviderException extends Exception {
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2023 Maxence Lange <maxence@artificial-owl.com>
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCP\OCM;
|
||||
|
||||
use OCP\OCM\Exceptions\OCMProviderException;
|
||||
|
||||
/**
|
||||
* Discover remote OCM services
|
||||
*
|
||||
* @since 28.0.0
|
||||
*/
|
||||
interface IOCMDiscoveryService {
|
||||
/**
|
||||
* Discover remote OCM services
|
||||
*
|
||||
* @param string $remote address of the remote provider
|
||||
* @param bool $skipCache ignore cache, refresh data
|
||||
*
|
||||
* @return IOCMProvider
|
||||
* @throws OCMProviderException if no valid discovery data can be returned
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function discover(string $remote, bool $skipCache = false): IOCMProvider;
|
||||
}
|
@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2023 Maxence Lange <maxence@artificial-owl.com>
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCP\OCM;
|
||||
|
||||
use OC\OCM\Model\OCMResource;
|
||||
use OCP\OCM\Exceptions\OCMArgumentException;
|
||||
use OCP\OCM\Exceptions\OCMProviderException;
|
||||
|
||||
/**
|
||||
* Model based on the Open Cloud Mesh Discovery API
|
||||
* @link https://github.com/cs3org/OCM-API/
|
||||
* @since 28.0.0
|
||||
*/
|
||||
interface IOCMProvider {
|
||||
/**
|
||||
* enable OCM
|
||||
*
|
||||
* @param bool $enabled
|
||||
*
|
||||
* @return self
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function setEnabled(bool $enabled): self;
|
||||
|
||||
/**
|
||||
* is set as enabled ?
|
||||
*
|
||||
* @return bool
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function isEnabled(): bool;
|
||||
|
||||
/**
|
||||
* get set API Version
|
||||
*
|
||||
* @param string $apiVersion
|
||||
*
|
||||
* @return self
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function setApiVersion(string $apiVersion): self;
|
||||
|
||||
/**
|
||||
* returns API version
|
||||
*
|
||||
* @return string
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function getApiVersion(): string;
|
||||
|
||||
/**
|
||||
* configure endpoint
|
||||
*
|
||||
* @param string $endPoint
|
||||
*
|
||||
* @return self
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function setEndPoint(string $endPoint): self;
|
||||
|
||||
/**
|
||||
* get configured endpoint
|
||||
*
|
||||
* @return string
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function getEndPoint(): string;
|
||||
|
||||
/**
|
||||
* add a single resource to the object
|
||||
*
|
||||
* @param OCMResource $resource
|
||||
*
|
||||
* @return self
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function addResourceType(OCMResource $resource): self;
|
||||
|
||||
/**
|
||||
* set resources
|
||||
*
|
||||
* @param OCMResource[] $resourceTypes
|
||||
*
|
||||
* @return self
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function setResourceTypes(array $resourceTypes): self;
|
||||
|
||||
/**
|
||||
* get all set resources
|
||||
*
|
||||
* @return IOCMResource[]
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function getResourceTypes(): array;
|
||||
|
||||
/**
|
||||
* extract a specific string value from the listing of protocols, based on resource-name and protocol-name
|
||||
*
|
||||
* @param string $resourceName
|
||||
* @param string $protocol
|
||||
*
|
||||
* @return string
|
||||
* @throws OCMArgumentException
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function extractProtocolEntry(string $resourceName, string $protocol): string;
|
||||
|
||||
/**
|
||||
* import data from an array
|
||||
*
|
||||
* @param array<string, int|string|bool|array> $data
|
||||
*
|
||||
* @return self
|
||||
* @throws OCMProviderException in case a descent provider cannot be generated from data
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function import(array $data): self;
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2023 Maxence Lange <maxence@artificial-owl.com>
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCP\OCM;
|
||||
|
||||
/**
|
||||
* Model based on the Open Cloud Mesh Discovery API
|
||||
*
|
||||
* @link https://github.com/cs3org/OCM-API/
|
||||
* @since 28.0.0
|
||||
*/
|
||||
interface IOCMResource {
|
||||
/**
|
||||
* set name of the resource
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return self
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function setName(string $name): self;
|
||||
|
||||
/**
|
||||
* get name of the resource
|
||||
*
|
||||
* @return string
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function getName(): string;
|
||||
|
||||
/**
|
||||
* set share types
|
||||
*
|
||||
* @param string[] $shareTypes
|
||||
*
|
||||
* @return self
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function setShareTypes(array $shareTypes): self;
|
||||
|
||||
/**
|
||||
* get share types
|
||||
*
|
||||
* @return string[]
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function getShareTypes(): array;
|
||||
|
||||
/**
|
||||
* set available protocols
|
||||
*
|
||||
* @param array<string, string> $protocols
|
||||
*
|
||||
* @return self
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function setProtocols(array $protocols): self;
|
||||
|
||||
/**
|
||||
* get configured protocols
|
||||
*
|
||||
* @return array<string, string>
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function getProtocols(): array;
|
||||
|
||||
/**
|
||||
* import data from an array
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return self
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function import(array $data): self;
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2018 Bjoern Schiessle <bjoern@schiessle.org>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
require_once __DIR__ . '/../lib/base.php';
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$server = \OC::$server;
|
||||
|
||||
$isEnabled = $server->getAppManager()->isEnabledForUser('cloud_federation_api');
|
||||
|
||||
if ($isEnabled) {
|
||||
// Make sure the routes are loaded
|
||||
\OC_App::loadApp('cloud_federation_api');
|
||||
$capabilities = new OCA\CloudFederationAPI\Capabilities($server->getURLGenerator());
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($capabilities->getCapabilities()['ocm']);
|
||||
} else {
|
||||
header($_SERVER["SERVER_PROTOCOL"]." 501 Not Implemented", true, 501);
|
||||
exit("501 Not Implemented");
|
||||
}
|
Loading…
Reference in New Issue