Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable26] ocm services #40592

Merged
merged 1 commit into from Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions apps/cloud_federation_api/appinfo/routes.php
Expand Up @@ -6,6 +6,7 @@
* @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
* @author Maxence Lange <maxence@artificial-owl.com>
*
* @license GNU AGPL version 3 or any later version
*
Expand All @@ -27,15 +28,21 @@
'routes' => [
[
'name' => 'RequestHandler#addShare',
'url' => '/ocm/shares',
'url' => '/shares',
'verb' => 'POST',
'root' => '',
'root' => '/ocm',
],
[
'name' => 'RequestHandler#receiveNotification',
'url' => '/ocm/notifications',
'url' => '/notifications',
'verb' => 'POST',
'root' => '',
'root' => '/ocm',
],
// [
// 'name' => 'RequestHandler#inviteAccepted',
// 'url' => '/invite-accepted',
// 'verb' => 'POST',
// 'root' => '/ocm',
// ]
],
];
65 changes: 42 additions & 23 deletions apps/cloud_federation_api/lib/Capabilities.php
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2017 Bjoern Schiessle <bjoern@schiessle.org>
*
Expand All @@ -20,45 +23,61 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

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;

class Capabilities implements ICapability {

/** @var IURLGenerator */
private $urlGenerator;
public const API_VERSION = '1.0-proposal1';

public function __construct(IURLGenerator $urlGenerator) {
$this->urlGenerator = $urlGenerator;
public function __construct(
private IURLGenerator $urlGenerator,
) {
}

/**
* Function an app uses to return the capabilities
*
* @return array Array containing the apps capabilities
* @since 8.2.0
* @return array{
* ocm: array{
* enabled: bool,
* apiVersion: string,
* endPoint: string,
* resourceTypes: array{
* name: string,
* shareTypes: string[],
* protocols: array<string, string>
* }[],
* },
* }
* @throws OCMArgumentException
*/
public function getCapabilities() {
$url = $this->urlGenerator->linkToRouteAbsolute('cloud_federation_api.requesthandlercontroller.addShare');
$capabilities = ['ocm' =>
[
'enabled' => true,
'apiVersion' => '1.0-proposal1',
'endPoint' => substr($url, 0, strrpos($url, '/')),
'resourceTypes' => [
[
'name' => 'file',
'shareTypes' => ['user', 'group'],
'protocols' => [
'webdav' => '/public.php/webdav/',
]
],
]
]
];
$provider = new OCMProvider();
$provider->setEnabled(true);
$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));

$resource = new OCMResource();
$resource->setName('file')
->setShareTypes(['user', 'group'])
->setProtocols(['webdav' => '/public.php/webdav/']);

$provider->setResourceTypes([$resource]);

return $capabilities;
return ['ocm' => $provider->jsonSerialize()];
}
}
Expand Up @@ -4,6 +4,7 @@
*
* @author Bjoern Schiessle <bjoern@schiessle.org>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Maxence Lange <maxence@artificial-owl.com>
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
Expand Down Expand Up @@ -51,52 +52,19 @@
* @package OCA\CloudFederationAPI\Controller
*/
class RequestHandlerController extends Controller {

/** @var LoggerInterface */
private $logger;

/** @var IUserManager */
private $userManager;

/** @var IGroupManager */
private $groupManager;

/** @var IURLGenerator */
private $urlGenerator;

/** @var ICloudFederationProviderManager */
private $cloudFederationProviderManager;

/** @var Config */
private $config;

/** @var ICloudFederationFactory */
private $factory;

/** @var ICloudIdManager */
private $cloudIdManager;

public function __construct($appName,
IRequest $request,
LoggerInterface $logger,
IUserManager $userManager,
IGroupManager $groupManager,
IURLGenerator $urlGenerator,
ICloudFederationProviderManager $cloudFederationProviderManager,
Config $config,
ICloudFederationFactory $factory,
ICloudIdManager $cloudIdManager
public function __construct(
string $appName,
IRequest $request,
private LoggerInterface $logger,
private IUserManager $userManager,
private IGroupManager $groupManager,
private IURLGenerator $urlGenerator,
private ICloudFederationProviderManager $cloudFederationProviderManager,
private Config $config,
private ICloudFederationFactory $factory,
private ICloudIdManager $cloudIdManager
) {
parent::__construct($appName, $request);

$this->logger = $logger;
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->urlGenerator = $urlGenerator;
$this->cloudFederationProviderManager = $cloudFederationProviderManager;
$this->config = $config;
$this->factory = $factory;
$this->cloudIdManager = $cloudIdManager;
}

/**
Expand All @@ -122,7 +90,6 @@ public function __construct($appName,
* Example: curl -H "Content-Type: application/json" -X POST -d '{"shareWith":"admin1@serve1","name":"welcome server2.txt","description":"desc","providerId":"2","owner":"admin2@http://localhost/server2","ownerDisplayName":"admin2 display","shareType":"user","resourceType":"file","protocol":{"name":"webdav","options":{"sharedSecret":"secret","permissions":"webdav-property"}}}' http://localhost/server/index.php/ocm/shares
*/
public function addShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $protocol, $shareType, $resourceType) {

// check if all required parameters are set
if ($shareWith === null ||
$name === null ||
Expand Down Expand Up @@ -281,7 +248,7 @@ public function receiveNotification($notificationType, $resourceType, $providerI
);
}

return new JSONResponse($result,Http::STATUS_CREATED);
return new JSONResponse($result, Http::STATUS_CREATED);
}

/**
Expand Down
28 changes: 17 additions & 11 deletions apps/files_sharing/lib/BackgroundJob/FederatedSharesDiscoverJob.php
Expand Up @@ -6,6 +6,7 @@
* @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Maxence Lange <maxence@artificial-owl.com>
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
Expand All @@ -29,21 +30,21 @@
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCP\IDBConnection;
use OCP\OCM\Exceptions\OCMProviderException;
use OCP\OCM\IOCMDiscoveryService;
use OCP\OCS\IDiscoveryService;
use Psr\Log\LoggerInterface;

class FederatedSharesDiscoverJob extends TimedJob {
/** @var IDBConnection */
private $connection;
/** @var IDiscoveryService */
private $discoveryService;

public function __construct(ITimeFactory $time,
IDBConnection $connection,
IDiscoveryService $discoveryService) {
parent::__construct($time);
$this->connection = $connection;
$this->discoveryService = $discoveryService;

public function __construct(
ITimeFactory $time,
private IDBConnection $connection,
private IDiscoveryService $discoveryService,
private IOCMDiscoveryService $ocmDiscoveryService,
private LoggerInterface $logger,
) {
parent::__construct($time);
$this->setInterval(86400);
}

Expand All @@ -56,6 +57,11 @@ public function run($argument) {
$result = $qb->execute();
while ($row = $result->fetch()) {
$this->discoveryService->discover($row['remote'], 'FEDERATED_SHARING', true);
try {
$this->ocmDiscoveryService->discover($row['remote'], true);
} catch (OCMProviderException $e) {
$this->logger->info('exception while running files_sharing/lib/BackgroundJob/FederatedSharesDiscoverJob', ['exception' => $e]);
}
}
$result->closeCursor();
}
Expand Down
Expand Up @@ -134,14 +134,14 @@ public function testRemote($remote) {
}

if (
$this->testUrl('https://' . $remote . '/ocs-provider/') ||
$this->testUrl('https://' . $remote . '/ocs-provider/index.php') ||
$this->testUrl('https://' . $remote . '/ocm-provider/') ||
$this->testUrl('https://' . $remote . '/ocm-provider/index.php') ||
$this->testUrl('https://' . $remote . '/status.php', true)
) {
return new DataResponse('https');
} elseif (
$this->testUrl('http://' . $remote . '/ocs-provider/') ||
$this->testUrl('http://' . $remote . '/ocs-provider/index.php') ||
$this->testUrl('http://' . $remote . '/ocm-provider/') ||
$this->testUrl('http://' . $remote . '/ocm-provider/index.php') ||
$this->testUrl('http://' . $remote . '/status.php', true)
) {
return new DataResponse('http');
Expand Down