Swift.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Files_External\Lib\Backend;
  8. use OCA\Files_External\Lib\Auth\AuthMechanism;
  9. use OCA\Files_External\Lib\Auth\OpenStack\OpenStackV2;
  10. use OCA\Files_External\Lib\Auth\OpenStack\Rackspace;
  11. use OCA\Files_External\Lib\DefinitionParameter;
  12. use OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;
  13. use OCP\IL10N;
  14. class Swift extends Backend {
  15. use LegacyDependencyCheckPolyfill;
  16. public function __construct(IL10N $l, OpenStackV2 $openstackAuth, Rackspace $rackspaceAuth) {
  17. $this
  18. ->setIdentifier('swift')
  19. ->addIdentifierAlias('\OC\Files\Storage\Swift') // legacy compat
  20. ->setStorageClass('\OCA\Files_External\Lib\Storage\Swift')
  21. ->setText($l->t('OpenStack Object Storage'))
  22. ->addParameters([
  23. (new DefinitionParameter('service_name', $l->t('Service name')))
  24. ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
  25. new DefinitionParameter('region', $l->t('Region')),
  26. new DefinitionParameter('bucket', $l->t('Bucket')),
  27. (new DefinitionParameter('timeout', $l->t('Request timeout (seconds)')))
  28. ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
  29. ])
  30. ->addAuthScheme(AuthMechanism::SCHEME_OPENSTACK)
  31. ->setLegacyAuthMechanismCallback(function (array $params) use ($openstackAuth, $rackspaceAuth) {
  32. if (isset($params['options']['key']) && $params['options']['key']) {
  33. return $rackspaceAuth;
  34. }
  35. return $openstackAuth;
  36. })
  37. ;
  38. }
  39. }