Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl committed Sep 20, 2023
1 parent c6c06d5 commit b5dcd04
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@
use OCP\OCM\Exceptions\OCMProviderException;
use OCP\OCM\IOCMDiscoveryService;
use OCP\OCS\IDiscoveryService;
use Psr\Log\LoggerInterface;

class FederatedSharesDiscoverJob extends TimedJob {

public function __construct(
ITimeFactory $time,
private IDBConnection $connection,
private IDiscoveryService $discoveryService,
private IOCMDiscoveryService $ocmDiscoveryService
private IOCMDiscoveryService $ocmDiscoveryService,
private LoggerInterface $logger,
) {
parent::__construct($time);
$this->setInterval(86400);
Expand All @@ -58,6 +60,7 @@ public function run($argument) {
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
5 changes: 0 additions & 5 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@
<code>IEventListener</code>
</MissingTemplateParam>
</file>
<file src="apps/cloud_federation_api/lib/Capabilities.php">
<LessSpecificImplementedReturnType>
<code>array</code>
</LessSpecificImplementedReturnType>
</file>
<file src="apps/comments/lib/Listener/CommentsEntityEventListener.php">
<MissingTemplateParam>
<code>IEventListener</code>
Expand Down
16 changes: 11 additions & 5 deletions core/Controller/OCMController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@
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\Capabilities\ICapability;
use OCP\IConfig;
use OCP\IRequest;
use OCP\Server;
Expand All @@ -58,11 +57,14 @@ public function __construct(
*
* @PublicPage
* @NoCSRFRequired
* @psalm-suppress MoreSpecificReturnType
* @psalm-suppress LessSpecificReturnStatement
* @return DataResponse<Http::STATUS_OK, array{enabled: bool, apiVersion: string, endPoint: string, resourceTypes: array{array{name: string, shareTypes: string[], protocols: array{webdav: string}}}}, array{X-NEXTCLOUD-OCM-PROVIDERS: true, Content-Type: 'application/json'}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}>
*
* @return Response
* 200: OCM Provider details returned
* 500: OCM not supported
*/
#[IgnoreOpenAPI]
public function discovery(): Response {
public function discovery(): DataResponse {
try {
$cap = Server::get(
$this->config->getAppValue(
Expand All @@ -72,6 +74,10 @@ public function discovery(): Response {
)
);

if (!($cap instanceof ICapability)) {
throw new Exception('loaded class does not implements OCP\Capabilities\ICapability');
}

return new DataResponse(
$cap->getCapabilities()['ocm'] ?? ['enabled' => false],
Http::STATUS_OK,
Expand Down
110 changes: 110 additions & 0 deletions core/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,116 @@
}
}
},
"/index.php/ocm-provider": {
"get": {
"operationId": "ocm-discovery",
"summary": "generate a OCMProvider with local data and send it as DataResponse. This replaces the old PHP file ocm-provider/index.php",
"tags": [
"ocm"
],
"security": [
{},
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"responses": {
"200": {
"description": "OCM Provider details returned",
"headers": {
"X-NEXTCLOUD-OCM-PROVIDERS": {
"schema": {
"type": "boolean"
}
}
},
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"enabled",
"apiVersion",
"endPoint",
"resourceTypes"
],
"properties": {
"enabled": {
"type": "boolean"
},
"apiVersion": {
"type": "string"
},
"endPoint": {
"type": "string"
},
"resourceTypes": {
"type": "object",
"required": [
null
],
"properties": {
"": {
"type": "object",
"required": [
"name",
"shareTypes",
"protocols"
],
"properties": {
"name": {
"type": "string"
},
"shareTypes": {
"type": "array",
"items": {
"type": "string"
}
},
"protocols": {
"type": "object",
"required": [
"webdav"
],
"properties": {
"webdav": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
},
"500": {
"description": "OCM not supported",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"message"
],
"properties": {
"message": {
"type": "string"
}
}
}
}
}
}
}
}
},
"/ocs/v2.php/cloud/capabilities": {
"get": {
"operationId": "ocs-get-capabilities",
Expand Down
2 changes: 1 addition & 1 deletion lib/private/OCM/Model/OCMProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private function looksValid(): bool {
* }
*/
public function jsonSerialize(): array {
$resourceTypes = []; // this is needed for psalm
$resourceTypes = [];
foreach ($this->getResourceTypes() as $res) {
$resourceTypes[] = $res->jsonSerialize();
}
Expand Down

0 comments on commit b5dcd04

Please sign in to comment.