Skip to content

Commit 429397b

Browse files
committed
ocm services
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent 110b784 commit 429397b

24 files changed

Lines changed: 1127 additions & 243 deletions

apps/cloud_federation_api/appinfo/routes.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com>
77
*
88
* @author Joas Schilling <coding@schilljs.com>
9+
* @author Maxence Lange <maxence@artificial-owl.com>
910
*
1011
* @license GNU AGPL version 3 or any later version
1112
*
@@ -27,15 +28,21 @@
2728
'routes' => [
2829
[
2930
'name' => 'RequestHandler#addShare',
30-
'url' => '/ocm/shares',
31+
'url' => '/shares',
3132
'verb' => 'POST',
32-
'root' => '',
33+
'root' => '/ocm',
3334
],
3435
[
3536
'name' => 'RequestHandler#receiveNotification',
36-
'url' => '/ocm/notifications',
37+
'url' => '/notifications',
3738
'verb' => 'POST',
38-
'root' => '',
39+
'root' => '/ocm',
3940
],
41+
// [
42+
// 'name' => 'RequestHandler#inviteAccepted',
43+
// 'url' => '/invite-accepted',
44+
// 'verb' => 'POST',
45+
// 'root' => '/ocm',
46+
// ]
4047
],
4148
];
Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
/**
36
* @copyright Copyright (c) 2017 Bjoern Schiessle <bjoern@schiessle.org>
47
*
@@ -20,45 +23,61 @@
2023
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2124
*
2225
*/
26+
2327
namespace OCA\CloudFederationAPI;
2428

29+
use OC\OCM\Model\OCMProvider;
30+
use OC\OCM\Model\OCMResource;
2531
use OCP\Capabilities\ICapability;
2632
use OCP\IURLGenerator;
33+
use OCP\OCM\Exceptions\OCMArgumentException;
2734

2835
class Capabilities implements ICapability {
2936

30-
/** @var IURLGenerator */
31-
private $urlGenerator;
37+
public const API_VERSION = '1.0-proposal1';
3238

33-
public function __construct(IURLGenerator $urlGenerator) {
34-
$this->urlGenerator = $urlGenerator;
39+
public function __construct(
40+
private IURLGenerator $urlGenerator,
41+
) {
3542
}
3643

3744
/**
3845
* Function an app uses to return the capabilities
3946
*
40-
* @return array Array containing the apps capabilities
41-
* @since 8.2.0
47+
* @return array{
48+
* ocm: array{
49+
* enabled: bool,
50+
* apiVersion: string,
51+
* endPoint: string,
52+
* resourceTypes: array{
53+
* name: string,
54+
* shareTypes: string[],
55+
* protocols: array<string, string>
56+
* }[],
57+
* },
58+
* }
59+
* @throws OCMArgumentException
4260
*/
4361
public function getCapabilities() {
4462
$url = $this->urlGenerator->linkToRouteAbsolute('cloud_federation_api.requesthandlercontroller.addShare');
45-
$capabilities = ['ocm' =>
46-
[
47-
'enabled' => true,
48-
'apiVersion' => '1.0-proposal1',
49-
'endPoint' => substr($url, 0, strrpos($url, '/')),
50-
'resourceTypes' => [
51-
[
52-
'name' => 'file',
53-
'shareTypes' => ['user', 'group'],
54-
'protocols' => [
55-
'webdav' => '/public.php/webdav/',
56-
]
57-
],
58-
]
59-
]
60-
];
63+
$provider = new OCMProvider();
64+
$provider->setEnabled(true);
65+
$provider->setApiVersion(self::API_VERSION);
66+
67+
$pos = strrpos($url, '/');
68+
if (false === $pos) {
69+
throw new OCMArgumentException('generated route should contains a slash character');
70+
}
71+
72+
$provider->setEndPoint(substr($url, 0, $pos));
73+
74+
$resource = new OCMResource();
75+
$resource->setName('file')
76+
->setShareTypes(['user', 'group'])
77+
->setProtocols(['webdav' => '/public.php/webdav/']);
78+
79+
$provider->setResourceTypes([$resource]);
6180

62-
return $capabilities;
81+
return ['ocm' => $provider->jsonSerialize()];
6382
}
6483
}

apps/cloud_federation_api/lib/Controller/RequestHandlerController.php

Lines changed: 13 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
* @author Bjoern Schiessle <bjoern@schiessle.org>
66
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
7+
* @author Maxence Lange <maxence@artificial-owl.com>
78
* @author Roeland Jago Douma <roeland@famdouma.nl>
89
*
910
* @license GNU AGPL version 3 or any later version
@@ -51,52 +52,19 @@
5152
* @package OCA\CloudFederationAPI\Controller
5253
*/
5354
class RequestHandlerController extends Controller {
54-
55-
/** @var LoggerInterface */
56-
private $logger;
57-
58-
/** @var IUserManager */
59-
private $userManager;
60-
61-
/** @var IGroupManager */
62-
private $groupManager;
63-
64-
/** @var IURLGenerator */
65-
private $urlGenerator;
66-
67-
/** @var ICloudFederationProviderManager */
68-
private $cloudFederationProviderManager;
69-
70-
/** @var Config */
71-
private $config;
72-
73-
/** @var ICloudFederationFactory */
74-
private $factory;
75-
76-
/** @var ICloudIdManager */
77-
private $cloudIdManager;
78-
79-
public function __construct($appName,
80-
IRequest $request,
81-
LoggerInterface $logger,
82-
IUserManager $userManager,
83-
IGroupManager $groupManager,
84-
IURLGenerator $urlGenerator,
85-
ICloudFederationProviderManager $cloudFederationProviderManager,
86-
Config $config,
87-
ICloudFederationFactory $factory,
88-
ICloudIdManager $cloudIdManager
55+
public function __construct(
56+
string $appName,
57+
IRequest $request,
58+
private LoggerInterface $logger,
59+
private IUserManager $userManager,
60+
private IGroupManager $groupManager,
61+
private IURLGenerator $urlGenerator,
62+
private ICloudFederationProviderManager $cloudFederationProviderManager,
63+
private Config $config,
64+
private ICloudFederationFactory $factory,
65+
private ICloudIdManager $cloudIdManager
8966
) {
9067
parent::__construct($appName, $request);
91-
92-
$this->logger = $logger;
93-
$this->userManager = $userManager;
94-
$this->groupManager = $groupManager;
95-
$this->urlGenerator = $urlGenerator;
96-
$this->cloudFederationProviderManager = $cloudFederationProviderManager;
97-
$this->config = $config;
98-
$this->factory = $factory;
99-
$this->cloudIdManager = $cloudIdManager;
10068
}
10169

10270
/**
@@ -122,7 +90,6 @@ public function __construct($appName,
12290
* 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
12391
*/
12492
public function addShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $protocol, $shareType, $resourceType) {
125-
12693
// check if all required parameters are set
12794
if ($shareWith === null ||
12895
$name === null ||
@@ -281,7 +248,7 @@ public function receiveNotification($notificationType, $resourceType, $providerI
281248
);
282249
}
283250

284-
return new JSONResponse($result,Http::STATUS_CREATED);
251+
return new JSONResponse($result, Http::STATUS_CREATED);
285252
}
286253

287254
/**

apps/files_sharing/lib/BackgroundJob/FederatedSharesDiscoverJob.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
77
*
88
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
9+
* @author Maxence Lange <maxence@artificial-owl.com>
910
* @author Roeland Jago Douma <roeland@famdouma.nl>
1011
*
1112
* @license GNU AGPL version 3 or any later version
@@ -29,21 +30,21 @@
2930
use OCP\AppFramework\Utility\ITimeFactory;
3031
use OCP\BackgroundJob\TimedJob;
3132
use OCP\IDBConnection;
33+
use OCP\OCM\Exceptions\OCMProviderException;
34+
use OCP\OCM\IOCMDiscoveryService;
3235
use OCP\OCS\IDiscoveryService;
36+
use Psr\Log\LoggerInterface;
3337

3438
class FederatedSharesDiscoverJob extends TimedJob {
35-
/** @var IDBConnection */
36-
private $connection;
37-
/** @var IDiscoveryService */
38-
private $discoveryService;
39-
40-
public function __construct(ITimeFactory $time,
41-
IDBConnection $connection,
42-
IDiscoveryService $discoveryService) {
43-
parent::__construct($time);
44-
$this->connection = $connection;
45-
$this->discoveryService = $discoveryService;
4639

40+
public function __construct(
41+
ITimeFactory $time,
42+
private IDBConnection $connection,
43+
private IDiscoveryService $discoveryService,
44+
private IOCMDiscoveryService $ocmDiscoveryService,
45+
private LoggerInterface $logger,
46+
) {
47+
parent::__construct($time);
4748
$this->setInterval(86400);
4849
}
4950

@@ -56,6 +57,11 @@ public function run($argument) {
5657
$result = $qb->execute();
5758
while ($row = $result->fetch()) {
5859
$this->discoveryService->discover($row['remote'], 'FEDERATED_SHARING', true);
60+
try {
61+
$this->ocmDiscoveryService->discover($row['remote'], true);
62+
} catch (OCMProviderException $e) {
63+
$this->logger->info('exception while running files_sharing/lib/BackgroundJob/FederatedSharesDiscoverJob', ['exception' => $e]);
64+
}
5965
}
6066
$result->closeCursor();
6167
}

apps/files_sharing/lib/Controller/ExternalSharesController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,14 @@ public function testRemote($remote) {
134134
}
135135

136136
if (
137-
$this->testUrl('https://' . $remote . '/ocs-provider/') ||
138-
$this->testUrl('https://' . $remote . '/ocs-provider/index.php') ||
137+
$this->testUrl('https://' . $remote . '/ocm-provider/') ||
138+
$this->testUrl('https://' . $remote . '/ocm-provider/index.php') ||
139139
$this->testUrl('https://' . $remote . '/status.php', true)
140140
) {
141141
return new DataResponse('https');
142142
} elseif (
143-
$this->testUrl('http://' . $remote . '/ocs-provider/') ||
144-
$this->testUrl('http://' . $remote . '/ocs-provider/index.php') ||
143+
$this->testUrl('http://' . $remote . '/ocm-provider/') ||
144+
$this->testUrl('http://' . $remote . '/ocm-provider/index.php') ||
145145
$this->testUrl('http://' . $remote . '/status.php', true)
146146
) {
147147
return new DataResponse('http');

0 commit comments

Comments
 (0)