Skip to content

Commit

Permalink
ocm controller
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <[email protected]>
  • Loading branch information
ArtificialOwl committed Jul 26, 2023
1 parent 19e7704 commit cf657da
Show file tree
Hide file tree
Showing 23 changed files with 1,005 additions and 195 deletions.
16 changes: 12 additions & 4 deletions apps/cloud_federation_api/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @copyright Copyright (c) 2020 Joas Schilling <[email protected]>
*
* @author Joas Schilling <[email protected]>
* @author Maxence Lange <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
Expand All @@ -27,15 +28,22 @@
'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',
],
// 1.1.0
// [
// 'name' => 'RequestHandler#inviteAccepted',
// 'url' => '/invite-accepted',
// 'verb' => 'POST',
// 'root' => '/ocm',
// ]
],
];
46 changes: 25 additions & 21 deletions apps/cloud_federation_api/lib/Capabilities.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2017 Bjoern Schiessle <[email protected]>
*
* @author Bjoern Schiessle <[email protected]>
* @author Kate Döen <[email protected]>
* @author Maxence Lange <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
Expand All @@ -23,16 +27,20 @@
*/
namespace OCA\CloudFederationAPI;

use OC\OCM\Model\OCMProvider;
use OC\OCM\Model\OCMResource;
use OCP\Capabilities\ICapability;
use OCP\IURLGenerator;
use OCP\OCM\IOCMDiscoveryService;

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,
private IOCMDiscoveryService $discoveryService
) {
}

/**
Expand All @@ -55,23 +63,19 @@ public function __construct(IURLGenerator $urlGenerator) {
*/
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/',
]
],
]
]
];

return $capabilities;
$provider = new OCMProvider();
$provider->setEnabled(true);
$provider->setApiVersion(self::API_VERSION);
$provider->setEndPoint(substr($url, 0, strrpos($url, '/')));

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

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

return ['ocm' => $provider];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\Response;
use OCP\Federation\Exceptions\ActionNotSupportedException;
use OCP\Federation\Exceptions\AuthenticationFailedException;
use OCP\Federation\Exceptions\BadRequestException;
Expand All @@ -56,51 +57,20 @@
*/
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 Down Expand Up @@ -314,6 +284,19 @@ public function receiveNotification($notificationType, $resourceType, $providerI
return new JSONResponse($result,Http::STATUS_CREATED);
}


// OCM 1.1.0
// /**
// *
// * @NoCSRFRequired
// * @PublicPage
// * @BruteForceProtection(action=federatedShareInvite)
// */
// public function inviteAccepted(): Response {
// return new Response([]);
// }


/**
* map login name to internal LDAP UID if a LDAP backend is in use
*
Expand Down
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit cf657da

Please sign in to comment.