Swift.php 2.3 KB

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