Swift.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Robin McCorkell <robin@mccorkell.me.uk>
  6. *
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OCA\Files_External\Lib\Backend;
  23. use \OCP\IL10N;
  24. use \OCA\Files_External\Lib\Backend\Backend;
  25. use \OCA\Files_External\Lib\DefinitionParameter;
  26. use \OCA\Files_External\Lib\Auth\AuthMechanism;
  27. use \OCA\Files_External\Service\BackendService;
  28. use \OCA\Files_External\Lib\Auth\OpenStack\OpenStack;
  29. use \OCA\Files_External\Lib\Auth\OpenStack\Rackspace;
  30. use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;
  31. class Swift extends Backend {
  32. use LegacyDependencyCheckPolyfill;
  33. public function __construct(IL10N $l, OpenStack $openstackAuth, Rackspace $rackspaceAuth) {
  34. $this
  35. ->setIdentifier('swift')
  36. ->addIdentifierAlias('\OC\Files\Storage\Swift') // legacy compat
  37. ->setStorageClass('\OCA\Files_External\Lib\Storage\Swift')
  38. ->setText($l->t('OpenStack Object Storage'))
  39. ->addParameters([
  40. (new DefinitionParameter('service_name', $l->t('Service name')))
  41. ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
  42. (new DefinitionParameter('region', $l->t('Region')))
  43. ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
  44. (new DefinitionParameter('bucket', $l->t('Bucket'))),
  45. (new DefinitionParameter('timeout', $l->t('Request timeout (seconds)')))
  46. ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
  47. ])
  48. ->addAuthScheme(AuthMechanism::SCHEME_OPENSTACK)
  49. ->setLegacyAuthMechanismCallback(function(array $params) use ($openstackAuth, $rackspaceAuth) {
  50. if (isset($params['options']['key']) && $params['options']['key']) {
  51. return $rackspaceAuth;
  52. }
  53. return $openstackAuth;
  54. })
  55. ;
  56. }
  57. }