-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
OCM Services #39574
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
Merged
Merged
OCM Services #39574
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| * | ||
|
|
@@ -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', | ||
| // ] | ||
| ], | ||
| ]; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| * | ||
|
|
@@ -21,18 +25,22 @@ | |
| * 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, | ||
| ) { | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -46,32 +54,33 @@ public function __construct(IURLGenerator $urlGenerator) { | |
| * resourceTypes: array{ | ||
| * name: string, | ||
| * shareTypes: string[], | ||
| * protocols: array{ | ||
| * webdav: 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/', | ||
| ] | ||
| ], | ||
| ] | ||
| ] | ||
| ]; | ||
|
|
||
| return $capabilities; | ||
| $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 ['ocm' => $provider->jsonSerialize()]; | ||
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| * | ||
| * @author Bjoern Schiessle <[email protected]> | ||
| * @author Christoph Wurst <[email protected]> | ||
| * @author Maxence Lange <[email protected]> | ||
| * @author Roeland Jago Douma <[email protected]> | ||
| * @author Kate Döen <[email protected]> | ||
| * | ||
|
|
@@ -55,52 +56,19 @@ | |
| * @psalm-import-type CloudFederationApiError from ResponseDefinitions | ||
| */ | ||
| 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; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -128,7 +96,6 @@ public function __construct($appName, | |
| * 501: Share type or the resource type is not supported | ||
| */ | ||
| 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 || | ||
|
|
@@ -253,7 +220,6 @@ public function addShare($shareWith, $name, $description, $providerId, $owner, $ | |
| * 501: The resource type is not supported | ||
| */ | ||
| public function receiveNotification($notificationType, $resourceType, $providerId, ?array $notification) { | ||
|
|
||
| // check if all required parameters are set | ||
| if ($notificationType === null || | ||
| $resourceType === null || | ||
|
|
@@ -311,7 +277,7 @@ public function receiveNotification($notificationType, $resourceType, $providerI | |
| ); | ||
| } | ||
|
|
||
| return new JSONResponse($result,Http::STATUS_CREATED); | ||
| return new JSONResponse($result, Http::STATUS_CREATED); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |||||||
| * @copyright 2018, Roeland Jago Douma <[email protected]> | ||||||||
| * | ||||||||
| * @author Christoph Wurst <[email protected]> | ||||||||
| * @author Maxence Lange <[email protected]> | ||||||||
| * @author Roeland Jago Douma <[email protected]> | ||||||||
| * | ||||||||
| * @license GNU AGPL version 3 or any later version | ||||||||
|
|
@@ -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); | ||||||||
| } | ||||||||
|
|
||||||||
|
|
@@ -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) { | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| $this->logger->info('exception while running files_sharing/lib/BackgroundJob/FederatedSharesDiscoverJob', ['exception' => $e]); | ||||||||
| } | ||||||||
| } | ||||||||
| $result->closeCursor(); | ||||||||
| } | ||||||||
|
|
||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.