You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OCMController.php 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2023 Maxence Lange <maxence@artificial-owl.com>
  5. *
  6. * @author Maxence Lange <maxence@artificial-owl.com>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OC\Core\Controller;
  25. use Exception;
  26. use OCP\AppFramework\Controller;
  27. use OCP\AppFramework\Http;
  28. use OCP\AppFramework\Http\Attribute\IgnoreOpenAPI;
  29. use OCP\AppFramework\Http\DataResponse;
  30. use OCP\AppFramework\Http\Response;
  31. use OCP\IConfig;
  32. use OCP\IRequest;
  33. use OCP\Server;
  34. use Psr\Container\ContainerExceptionInterface;
  35. use Psr\Log\LoggerInterface;
  36. /**
  37. * Controller about the endpoint /ocm-provider/
  38. *
  39. * @since 28.0.0
  40. */
  41. class OCMController extends Controller {
  42. public function __construct(
  43. IRequest $request,
  44. private IConfig $config,
  45. private LoggerInterface $logger
  46. ) {
  47. parent::__construct('core', $request);
  48. }
  49. /**
  50. * generate a OCMProvider with local data and send it as DataResponse.
  51. * This replaces the old PHP file ocm-provider/index.php
  52. *
  53. * @PublicPage
  54. * @NoCSRFRequired
  55. *
  56. * @return Response
  57. */
  58. #[IgnoreOpenAPI]
  59. public function discovery(): Response {
  60. try {
  61. $cap = Server::get(
  62. $this->config->getAppValue(
  63. 'core',
  64. 'ocm_providers',
  65. '\OCA\CloudFederationAPI\Capabilities'
  66. )
  67. );
  68. return new DataResponse(
  69. $cap->getCapabilities()['ocm'] ?? ['enabled' => false],
  70. Http::STATUS_OK,
  71. [
  72. 'X-NEXTCLOUD-OCM-PROVIDERS' => true,
  73. 'Content-Type' => 'application/json'
  74. ]
  75. );
  76. } catch (ContainerExceptionInterface|Exception $e) {
  77. $this->logger->error('issue during OCM discovery request', ['exception' => $e]);
  78. return new DataResponse(
  79. ['message' => '/ocm-provider/ not supported'],
  80. Http::STATUS_INTERNAL_SERVER_ERROR
  81. );
  82. }
  83. }
  84. }