From 6ea54e73e82fb02bb6bfa3a189a861f90c00d105 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 13 May 2016 11:42:01 +0200 Subject: Move Lib\Backend to PSR-4 --- apps/files_external/lib/Lib/Backend/AmazonS3.php | 61 ++++++++ apps/files_external/lib/Lib/Backend/Backend.php | 165 +++++++++++++++++++++ apps/files_external/lib/Lib/Backend/DAV.php | 55 +++++++ apps/files_external/lib/Lib/Backend/Dropbox.php | 52 +++++++ apps/files_external/lib/Lib/Backend/FTP.php | 55 +++++++ apps/files_external/lib/Lib/Backend/Google.php | 52 +++++++ .../lib/Lib/Backend/LegacyBackend.php | 104 +++++++++++++ apps/files_external/lib/Lib/Backend/Local.php | 49 ++++++ apps/files_external/lib/Lib/Backend/OwnCloud.php | 52 +++++++ apps/files_external/lib/Lib/Backend/SFTP.php | 51 +++++++ apps/files_external/lib/Lib/Backend/SFTP_Key.php | 50 +++++++ apps/files_external/lib/Lib/Backend/SMB.php | 69 +++++++++ apps/files_external/lib/Lib/Backend/SMB_OC.php | 72 +++++++++ apps/files_external/lib/Lib/Backend/Swift.php | 62 ++++++++ apps/files_external/lib/backend/amazons3.php | 61 -------- apps/files_external/lib/backend/backend.php | 165 --------------------- apps/files_external/lib/backend/dav.php | 55 ------- apps/files_external/lib/backend/dropbox.php | 52 ------- apps/files_external/lib/backend/ftp.php | 55 ------- apps/files_external/lib/backend/google.php | 52 ------- apps/files_external/lib/backend/legacybackend.php | 104 ------------- apps/files_external/lib/backend/local.php | 49 ------ apps/files_external/lib/backend/owncloud.php | 52 ------- apps/files_external/lib/backend/sftp.php | 51 ------- apps/files_external/lib/backend/sftp_key.php | 50 ------- apps/files_external/lib/backend/smb.php | 69 --------- apps/files_external/lib/backend/smb_oc.php | 72 --------- apps/files_external/lib/backend/swift.php | 62 -------- 28 files changed, 949 insertions(+), 949 deletions(-) create mode 100644 apps/files_external/lib/Lib/Backend/AmazonS3.php create mode 100644 apps/files_external/lib/Lib/Backend/Backend.php create mode 100644 apps/files_external/lib/Lib/Backend/DAV.php create mode 100644 apps/files_external/lib/Lib/Backend/Dropbox.php create mode 100644 apps/files_external/lib/Lib/Backend/FTP.php create mode 100644 apps/files_external/lib/Lib/Backend/Google.php create mode 100644 apps/files_external/lib/Lib/Backend/LegacyBackend.php create mode 100644 apps/files_external/lib/Lib/Backend/Local.php create mode 100644 apps/files_external/lib/Lib/Backend/OwnCloud.php create mode 100644 apps/files_external/lib/Lib/Backend/SFTP.php create mode 100644 apps/files_external/lib/Lib/Backend/SFTP_Key.php create mode 100644 apps/files_external/lib/Lib/Backend/SMB.php create mode 100644 apps/files_external/lib/Lib/Backend/SMB_OC.php create mode 100644 apps/files_external/lib/Lib/Backend/Swift.php delete mode 100644 apps/files_external/lib/backend/amazons3.php delete mode 100644 apps/files_external/lib/backend/backend.php delete mode 100644 apps/files_external/lib/backend/dav.php delete mode 100644 apps/files_external/lib/backend/dropbox.php delete mode 100644 apps/files_external/lib/backend/ftp.php delete mode 100644 apps/files_external/lib/backend/google.php delete mode 100644 apps/files_external/lib/backend/legacybackend.php delete mode 100644 apps/files_external/lib/backend/local.php delete mode 100644 apps/files_external/lib/backend/owncloud.php delete mode 100644 apps/files_external/lib/backend/sftp.php delete mode 100644 apps/files_external/lib/backend/sftp_key.php delete mode 100644 apps/files_external/lib/backend/smb.php delete mode 100644 apps/files_external/lib/backend/smb_oc.php delete mode 100644 apps/files_external/lib/backend/swift.php (limited to 'apps/files_external/lib') diff --git a/apps/files_external/lib/Lib/Backend/AmazonS3.php b/apps/files_external/lib/Lib/Backend/AmazonS3.php new file mode 100644 index 00000000000..449b6c0379d --- /dev/null +++ b/apps/files_external/lib/Lib/Backend/AmazonS3.php @@ -0,0 +1,61 @@ + + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OCA\Files_External\Lib\Backend; + +use \OCP\IL10N; +use \OCA\Files_External\Lib\Backend\Backend; +use \OCA\Files_External\Lib\DefinitionParameter; +use \OCA\Files_External\Lib\Auth\AuthMechanism; +use \OCA\Files_External\Service\BackendService; +use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; + +use \OCA\Files_External\Lib\Auth\AmazonS3\AccessKey; + +class AmazonS3 extends Backend { + + use LegacyDependencyCheckPolyfill; + + public function __construct(IL10N $l, AccessKey $legacyAuth) { + $this + ->setIdentifier('amazons3') + ->addIdentifierAlias('\OC\Files\Storage\AmazonS3') // legacy compat + ->setStorageClass('\OCA\Files_External\Lib\Storage\AmazonS3') + ->setText($l->t('Amazon S3')) + ->addParameters([ + (new DefinitionParameter('bucket', $l->t('Bucket'))), + (new DefinitionParameter('hostname', $l->t('Hostname'))) + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), + (new DefinitionParameter('port', $l->t('Port'))) + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), + (new DefinitionParameter('region', $l->t('Region'))) + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), + (new DefinitionParameter('use_ssl', $l->t('Enable SSL'))) + ->setType(DefinitionParameter::VALUE_BOOLEAN), + (new DefinitionParameter('use_path_style', $l->t('Enable Path Style'))) + ->setType(DefinitionParameter::VALUE_BOOLEAN), + ]) + ->addAuthScheme(AccessKey::SCHEME_AMAZONS3_ACCESSKEY) + ->setLegacyAuthMechanism($legacyAuth) + ; + } + +} diff --git a/apps/files_external/lib/Lib/Backend/Backend.php b/apps/files_external/lib/Lib/Backend/Backend.php new file mode 100644 index 00000000000..8fb84b0e835 --- /dev/null +++ b/apps/files_external/lib/Lib/Backend/Backend.php @@ -0,0 +1,165 @@ + + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OCA\Files_External\Lib\Backend; + +use \OCA\Files_External\Lib\StorageConfig; +use \OCA\Files_External\Lib\VisibilityTrait; +use \OCA\Files_External\Lib\FrontendDefinitionTrait; +use \OCA\Files_External\Lib\PriorityTrait; +use \OCA\Files_External\Lib\DependencyTrait; +use \OCA\Files_External\Lib\StorageModifierTrait; +use \OCA\Files_External\Lib\IdentifierTrait; +use \OCA\Files_External\Lib\Auth\AuthMechanism; + +/** + * Storage backend + * + * A backend can have services injected during construction, + * such as \OCP\IDB for database operations. This allows a backend + * to perform advanced operations based on provided information. + * + * An authenication scheme defines the parameter interface, common to the + * storage implementation, the backend and the authentication mechanism. + * A storage implementation expects parameters according to the authentication + * scheme, which are provided from the authentication mechanism. + * + * This class uses the following traits: + * - VisibilityTrait + * Restrict usage to admin-only/none + * - FrontendDefinitionTrait + * Specify configuration parameters and other definitions + * - PriorityTrait + * Allow objects to prioritize over others with the same mountpoint + * - DependencyTrait + * The object requires certain dependencies to be met + * - StorageModifierTrait + * Object can affect storage mounting + */ +class Backend implements \JsonSerializable { + + use VisibilityTrait; + use FrontendDefinitionTrait; + use PriorityTrait; + use DependencyTrait; + use StorageModifierTrait; + use IdentifierTrait; + + /** @var string storage class */ + private $storageClass; + + /** @var array 'scheme' => true, supported authentication schemes */ + private $authSchemes = []; + + /** @var AuthMechanism|callable authentication mechanism fallback */ + private $legacyAuthMechanism; + + /** + * @return string + */ + public function getStorageClass() { + return $this->storageClass; + } + + /** + * @param string $class + * @return self + */ + public function setStorageClass($class) { + $this->storageClass = $class; + return $this; + } + + /** + * @return array + */ + public function getAuthSchemes() { + if (empty($this->authSchemes)) { + return [AuthMechanism::SCHEME_NULL => true]; + } + return $this->authSchemes; + } + + /** + * @param string $scheme + * @return self + */ + public function addAuthScheme($scheme) { + $this->authSchemes[$scheme] = true; + return $this; + } + + /** + * @param array $parameters storage parameters, for dynamic mechanism selection + * @return AuthMechanism + */ + public function getLegacyAuthMechanism(array $parameters = []) { + if (is_callable($this->legacyAuthMechanism)) { + return call_user_func($this->legacyAuthMechanism, $parameters); + } + return $this->legacyAuthMechanism; + } + + /** + * @param AuthMechanism $authMechanism + * @return self + */ + public function setLegacyAuthMechanism(AuthMechanism $authMechanism) { + $this->legacyAuthMechanism = $authMechanism; + return $this; + } + + /** + * @param callable $callback dynamic auth mechanism selection + * @return self + */ + public function setLegacyAuthMechanismCallback(callable $callback) { + $this->legacyAuthMechanism = $callback; + } + + /** + * Serialize into JSON for client-side JS + * + * @return array + */ + public function jsonSerialize() { + $data = $this->jsonSerializeDefinition(); + $data += $this->jsonSerializeIdentifier(); + + $data['backend'] = $data['name']; // legacy compat + $data['priority'] = $this->getPriority(); + $data['authSchemes'] = $this->getAuthSchemes(); + + return $data; + } + + /** + * Check if parameters are satisfied in a StorageConfig + * + * @param StorageConfig $storage + * @return bool + */ + public function validateStorage(StorageConfig $storage) { + return $this->validateStorageDefinition($storage); + } + +} + diff --git a/apps/files_external/lib/Lib/Backend/DAV.php b/apps/files_external/lib/Lib/Backend/DAV.php new file mode 100644 index 00000000000..c6e9630be9e --- /dev/null +++ b/apps/files_external/lib/Lib/Backend/DAV.php @@ -0,0 +1,55 @@ + + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OCA\Files_External\Lib\Backend; + +use \OCP\IL10N; +use \OCA\Files_External\Lib\Backend\Backend; +use \OCA\Files_External\Lib\DefinitionParameter; +use \OCA\Files_External\Lib\Auth\AuthMechanism; +use \OCA\Files_External\Service\BackendService; +use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; + +use \OCA\Files_External\Lib\Auth\Password\Password; + +class DAV extends Backend { + + use LegacyDependencyCheckPolyfill; + + public function __construct(IL10N $l, Password $legacyAuth) { + $this + ->setIdentifier('dav') + ->addIdentifierAlias('\OC\Files\Storage\DAV') // legacy compat + ->setStorageClass('\OC\Files\Storage\DAV') + ->setText($l->t('WebDAV')) + ->addParameters([ + (new DefinitionParameter('host', $l->t('URL'))), + (new DefinitionParameter('root', $l->t('Remote subfolder'))) + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), + (new DefinitionParameter('secure', $l->t('Secure https://'))) + ->setType(DefinitionParameter::VALUE_BOOLEAN), + ]) + ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) + ->setLegacyAuthMechanism($legacyAuth) + ; + } + +} diff --git a/apps/files_external/lib/Lib/Backend/Dropbox.php b/apps/files_external/lib/Lib/Backend/Dropbox.php new file mode 100644 index 00000000000..2133c274996 --- /dev/null +++ b/apps/files_external/lib/Lib/Backend/Dropbox.php @@ -0,0 +1,52 @@ + + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OCA\Files_External\Lib\Backend; + +use \OCP\IL10N; +use \OCA\Files_External\Lib\Backend\Backend; +use \OCA\Files_External\Lib\DefinitionParameter; +use \OCA\Files_External\Lib\Auth\AuthMechanism; +use \OCA\Files_External\Service\BackendService; +use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; + +use \OCA\Files_External\Lib\Auth\OAuth1\OAuth1; + +class Dropbox extends Backend { + + use LegacyDependencyCheckPolyfill; + + public function __construct(IL10N $l, OAuth1 $legacyAuth) { + $this + ->setIdentifier('dropbox') + ->addIdentifierAlias('\OC\Files\Storage\Dropbox') // legacy compat + ->setStorageClass('\OCA\Files_External\Lib\Storage\Dropbox') + ->setText($l->t('Dropbox')) + ->addParameters([ + // all parameters handled in OAuth1 mechanism + ]) + ->addAuthScheme(AuthMechanism::SCHEME_OAUTH1) + ->addCustomJs('dropbox') + ->setLegacyAuthMechanism($legacyAuth) + ; + } + +} diff --git a/apps/files_external/lib/Lib/Backend/FTP.php b/apps/files_external/lib/Lib/Backend/FTP.php new file mode 100644 index 00000000000..3960592d0bc --- /dev/null +++ b/apps/files_external/lib/Lib/Backend/FTP.php @@ -0,0 +1,55 @@ + + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OCA\Files_External\Lib\Backend; + +use \OCP\IL10N; +use \OCA\Files_External\Lib\Backend\Backend; +use \OCA\Files_External\Lib\DefinitionParameter; +use \OCA\Files_External\Lib\Auth\AuthMechanism; +use \OCA\Files_External\Service\BackendService; +use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; + +use \OCA\Files_External\Lib\Auth\Password\Password; + +class FTP extends Backend { + + use LegacyDependencyCheckPolyfill; + + public function __construct(IL10N $l, Password $legacyAuth) { + $this + ->setIdentifier('ftp') + ->addIdentifierAlias('\OC\Files\Storage\FTP') // legacy compat + ->setStorageClass('\OCA\Files_External\Lib\Storage\FTP') + ->setText($l->t('FTP')) + ->addParameters([ + (new DefinitionParameter('host', $l->t('Host'))), + (new DefinitionParameter('root', $l->t('Remote subfolder'))) + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), + (new DefinitionParameter('secure', $l->t('Secure ftps://'))) + ->setType(DefinitionParameter::VALUE_BOOLEAN), + ]) + ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) + ->setLegacyAuthMechanism($legacyAuth) + ; + } + +} diff --git a/apps/files_external/lib/Lib/Backend/Google.php b/apps/files_external/lib/Lib/Backend/Google.php new file mode 100644 index 00000000000..b18b7bdb348 --- /dev/null +++ b/apps/files_external/lib/Lib/Backend/Google.php @@ -0,0 +1,52 @@ + + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OCA\Files_External\Lib\Backend; + +use \OCP\IL10N; +use \OCA\Files_External\Lib\Backend\Backend; +use \OCA\Files_External\Lib\DefinitionParameter; +use \OCA\Files_External\Lib\Auth\AuthMechanism; +use \OCA\Files_External\Service\BackendService; +use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; + +use \OCA\Files_External\Lib\Auth\OAuth2\OAuth2; + +class Google extends Backend { + + use LegacyDependencyCheckPolyfill; + + public function __construct(IL10N $l, OAuth2 $legacyAuth) { + $this + ->setIdentifier('googledrive') + ->addIdentifierAlias('\OC\Files\Storage\Google') // legacy compat + ->setStorageClass('\OCA\Files_External\Lib\Storage\Google') + ->setText($l->t('Google Drive')) + ->addParameters([ + // all parameters handled in OAuth2 mechanism + ]) + ->addAuthScheme(AuthMechanism::SCHEME_OAUTH2) + ->addCustomJs('gdrive') + ->setLegacyAuthMechanism($legacyAuth) + ; + } + +} diff --git a/apps/files_external/lib/Lib/Backend/LegacyBackend.php b/apps/files_external/lib/Lib/Backend/LegacyBackend.php new file mode 100644 index 00000000000..752c501e1ec --- /dev/null +++ b/apps/files_external/lib/Lib/Backend/LegacyBackend.php @@ -0,0 +1,104 @@ + + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OCA\Files_External\Lib\Backend; + +use \OCA\Files_External\Lib\DefinitionParameter; +use \OCA\Files_External\Lib\Backend\Backend; +use \OCA\Files_External\Lib\Auth\Builtin; +use \OCA\Files_External\Lib\MissingDependency; +use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; + +/** + * Legacy compatibility for OC_Mount_Config::registerBackend() + */ +class LegacyBackend extends Backend { + + use LegacyDependencyCheckPolyfill { + LegacyDependencyCheckPolyfill::checkDependencies as doCheckDependencies; + } + + /** @var bool */ + protected $hasDependencies = false; + + /** + * @param string $class + * @param array $definition + * @param Builtin $authMechanism + */ + public function __construct($class, array $definition, Builtin $authMechanism) { + $this + ->setIdentifier($class) + ->setStorageClass($class) + ->setText($definition['backend']) + ->addAuthScheme(Builtin::SCHEME_BUILTIN) + ->setLegacyAuthMechanism($authMechanism) + ; + + foreach ($definition['configuration'] as $name => $placeholder) { + $flags = DefinitionParameter::FLAG_NONE; + $type = DefinitionParameter::VALUE_TEXT; + if ($placeholder[0] === '&') { + $flags = DefinitionParameter::FLAG_OPTIONAL; + $placeholder = substr($placeholder, 1); + } + switch ($placeholder[0]) { + case '!': + $type = DefinitionParameter::VALUE_BOOLEAN; + $placeholder = substr($placeholder, 1); + break; + case '*': + $type = DefinitionParameter::VALUE_PASSWORD; + $placeholder = substr($placeholder, 1); + break; + case '#': + $type = DefinitionParameter::VALUE_HIDDEN; + $placeholder = substr($placeholder, 1); + break; + } + $this->addParameter((new DefinitionParameter($name, $placeholder)) + ->setType($type) + ->setFlags($flags) + ); + } + + if (isset($definition['priority'])) { + $this->setPriority($definition['priority']); + } + if (isset($definition['custom'])) { + $this->addCustomJs($definition['custom']); + } + if (isset($definition['has_dependencies']) && $definition['has_dependencies']) { + $this->hasDependencies = true; + } + } + + /** + * @return MissingDependency[] + */ + public function checkDependencies() { + if ($this->hasDependencies) { + return $this->doCheckDependencies(); + } + return []; + } + +} diff --git a/apps/files_external/lib/Lib/Backend/Local.php b/apps/files_external/lib/Lib/Backend/Local.php new file mode 100644 index 00000000000..1db707e7247 --- /dev/null +++ b/apps/files_external/lib/Lib/Backend/Local.php @@ -0,0 +1,49 @@ + + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OCA\Files_External\Lib\Backend; + +use \OCP\IL10N; +use \OCA\Files_External\Lib\Backend\Backend; +use \OCA\Files_External\Lib\DefinitionParameter; +use \OCA\Files_External\Lib\Auth\AuthMechanism; +use \OCA\Files_External\Service\BackendService; +use \OCA\Files_External\Lib\Auth\NullMechanism; + +class Local extends Backend { + + public function __construct(IL10N $l, NullMechanism $legacyAuth) { + $this + ->setIdentifier('local') + ->addIdentifierAlias('\OC\Files\Storage\Local') // legacy compat + ->setStorageClass('\OC\Files\Storage\Local') + ->setText($l->t('Local')) + ->addParameters([ + (new DefinitionParameter('datadir', $l->t('Location'))), + ]) + ->setAllowedVisibility(BackendService::VISIBILITY_ADMIN) + ->setPriority(BackendService::PRIORITY_DEFAULT + 50) + ->addAuthScheme(AuthMechanism::SCHEME_NULL) + ->setLegacyAuthMechanism($legacyAuth) + ; + } + +} diff --git a/apps/files_external/lib/Lib/Backend/OwnCloud.php b/apps/files_external/lib/Lib/Backend/OwnCloud.php new file mode 100644 index 00000000000..e92288b1354 --- /dev/null +++ b/apps/files_external/lib/Lib/Backend/OwnCloud.php @@ -0,0 +1,52 @@ + + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OCA\Files_External\Lib\Backend; + +use \OCP\IL10N; +use \OCA\Files_External\Lib\Backend\Backend; +use \OCA\Files_External\Lib\DefinitionParameter; +use \OCA\Files_External\Lib\Auth\AuthMechanism; +use \OCA\Files_External\Service\BackendService; + +use \OCA\Files_External\Lib\Auth\Password\Password; + +class OwnCloud extends Backend { + + public function __construct(IL10N $l, Password $legacyAuth) { + $this + ->setIdentifier('owncloud') + ->addIdentifierAlias('\OC\Files\Storage\OwnCloud') // legacy compat + ->setStorageClass('\OCA\Files_External\Lib\Storage\OwnCloud') + ->setText($l->t('ownCloud')) + ->addParameters([ + (new DefinitionParameter('host', $l->t('URL'))), + (new DefinitionParameter('root', $l->t('Remote subfolder'))) + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), + (new DefinitionParameter('secure', $l->t('Secure https://'))) + ->setType(DefinitionParameter::VALUE_BOOLEAN), + ]) + ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) + ->setLegacyAuthMechanism($legacyAuth) + ; + } + +} diff --git a/apps/files_external/lib/Lib/Backend/SFTP.php b/apps/files_external/lib/Lib/Backend/SFTP.php new file mode 100644 index 00000000000..fa33caeb576 --- /dev/null +++ b/apps/files_external/lib/Lib/Backend/SFTP.php @@ -0,0 +1,51 @@ + + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OCA\Files_External\Lib\Backend; + +use \OCP\IL10N; +use \OCA\Files_External\Lib\Backend\Backend; +use \OCA\Files_External\Lib\DefinitionParameter; +use \OCA\Files_External\Lib\Auth\AuthMechanism; +use \OCA\Files_External\Service\BackendService; + +use \OCA\Files_External\Lib\Auth\Password\Password; + +class SFTP extends Backend { + + public function __construct(IL10N $l, Password $legacyAuth) { + $this + ->setIdentifier('sftp') + ->addIdentifierAlias('\OC\Files\Storage\SFTP') // legacy compat + ->setStorageClass('\OCA\Files_External\Lib\Storage\SFTP') + ->setText($l->t('SFTP')) + ->addParameters([ + (new DefinitionParameter('host', $l->t('Host'))), + (new DefinitionParameter('root', $l->t('Root'))) + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), + ]) + ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) + ->addAuthScheme(AuthMechanism::SCHEME_PUBLICKEY) + ->setLegacyAuthMechanism($legacyAuth) + ; + } + +} diff --git a/apps/files_external/lib/Lib/Backend/SFTP_Key.php b/apps/files_external/lib/Lib/Backend/SFTP_Key.php new file mode 100644 index 00000000000..838cf6c52b2 --- /dev/null +++ b/apps/files_external/lib/Lib/Backend/SFTP_Key.php @@ -0,0 +1,50 @@ + + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OCA\Files_External\Lib\Backend; + +use \OCP\IL10N; +use \OCA\Files_External\Lib\Backend\Backend; +use \OCA\Files_External\Lib\DefinitionParameter; +use \OCA\Files_External\Lib\Auth\AuthMechanism; +use \OCA\Files_External\Service\BackendService; +use \OCA\Files_External\Lib\Auth\PublicKey\RSA; +use \OCA\Files_External\Lib\Backend\SFTP; + +class SFTP_Key extends Backend { + + public function __construct(IL10N $l, RSA $legacyAuth, SFTP $sftpBackend) { + $this + ->setIdentifier('\OC\Files\Storage\SFTP_Key') + ->setStorageClass('\OCA\Files_External\Lib\Storage\SFTP') + ->setText($l->t('SFTP with secret key login')) + ->addParameters([ + (new DefinitionParameter('host', $l->t('Host'))), + (new DefinitionParameter('root', $l->t('Remote subfolder'))) + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), + ]) + ->addAuthScheme(AuthMechanism::SCHEME_PUBLICKEY) + ->setLegacyAuthMechanism($legacyAuth) + ->deprecateTo($sftpBackend) + ; + } + +} diff --git a/apps/files_external/lib/Lib/Backend/SMB.php b/apps/files_external/lib/Lib/Backend/SMB.php new file mode 100644 index 00000000000..7ea30dd11bd --- /dev/null +++ b/apps/files_external/lib/Lib/Backend/SMB.php @@ -0,0 +1,69 @@ + + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OCA\Files_External\Lib\Backend; + +use \OCP\IL10N; +use \OCA\Files_External\Lib\Backend\Backend; +use \OCA\Files_External\Lib\DefinitionParameter; +use \OCA\Files_External\Lib\Auth\AuthMechanism; +use \OCA\Files_External\Service\BackendService; +use \OCA\Files_External\Lib\StorageConfig; +use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; + +use \OCA\Files_External\Lib\Auth\Password\Password; +use OCP\IUser; + +class SMB extends Backend { + + use LegacyDependencyCheckPolyfill; + + public function __construct(IL10N $l, Password $legacyAuth) { + $this + ->setIdentifier('smb') + ->addIdentifierAlias('\OC\Files\Storage\SMB') // legacy compat + ->setStorageClass('\OCA\Files_External\Lib\Storage\SMB') + ->setText($l->t('SMB / CIFS')) + ->addParameters([ + (new DefinitionParameter('host', $l->t('Host'))), + (new DefinitionParameter('share', $l->t('Share'))), + (new DefinitionParameter('root', $l->t('Remote subfolder'))) + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), + (new DefinitionParameter('domain', $l->t('Domain'))) + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), + ]) + ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) + ->setLegacyAuthMechanism($legacyAuth) + ; + } + + /** + * @param StorageConfig $storage + * @param IUser $user + */ + public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) { + $user = $storage->getBackendOption('user'); + if ($domain = $storage->getBackendOption('domain')) { + $storage->setBackendOption('user', $domain.'\\'.$user); + } + } + +} diff --git a/apps/files_external/lib/Lib/Backend/SMB_OC.php b/apps/files_external/lib/Lib/Backend/SMB_OC.php new file mode 100644 index 00000000000..c543a19bdd8 --- /dev/null +++ b/apps/files_external/lib/Lib/Backend/SMB_OC.php @@ -0,0 +1,72 @@ + + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OCA\Files_External\Lib\Backend; + +use \OCP\IL10N; +use \OCA\Files_External\Lib\Backend\Backend; +use \OCA\Files_External\Lib\DefinitionParameter; +use \OCA\Files_External\Lib\Auth\AuthMechanism; +use \OCA\Files_External\Service\BackendService; +use \OCA\Files_External\Lib\Auth\Password\SessionCredentials; +use \OCA\Files_External\Lib\StorageConfig; +use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; +use \OCA\Files_External\Lib\Backend\SMB; +use OCP\IUser; + +/** + * Deprecated SMB_OC class - use SMB with the password::sessioncredentials auth mechanism + */ +class SMB_OC extends Backend { + + use LegacyDependencyCheckPolyfill; + + public function __construct(IL10N $l, SessionCredentials $legacyAuth, SMB $smbBackend) { + $this + ->setIdentifier('\OC\Files\Storage\SMB_OC') + ->setStorageClass('\OCA\Files_External\Lib\Storage\SMB') + ->setText($l->t('SMB / CIFS using OC login')) + ->addParameters([ + (new DefinitionParameter('host', $l->t('Host'))), + (new DefinitionParameter('username_as_share', $l->t('Username as share'))) + ->setType(DefinitionParameter::VALUE_BOOLEAN), + (new DefinitionParameter('share', $l->t('Share'))) + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), + (new DefinitionParameter('root', $l->t('Remote subfolder'))) + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), + ]) + ->setPriority(BackendService::PRIORITY_DEFAULT - 10) + ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) + ->setLegacyAuthMechanism($legacyAuth) + ->deprecateTo($smbBackend) + ; + } + + public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) { + $username_as_share = ($storage->getBackendOption('username_as_share') === true); + + if ($username_as_share) { + $share = '/' . $storage->getBackendOption('user'); + $storage->setBackendOption('share', $share); + } + } + +} diff --git a/apps/files_external/lib/Lib/Backend/Swift.php b/apps/files_external/lib/Lib/Backend/Swift.php new file mode 100644 index 00000000000..58677575f52 --- /dev/null +++ b/apps/files_external/lib/Lib/Backend/Swift.php @@ -0,0 +1,62 @@ + + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OCA\Files_External\Lib\Backend; + +use \OCP\IL10N; +use \OCA\Files_External\Lib\Backend\Backend; +use \OCA\Files_External\Lib\DefinitionParameter; +use \OCA\Files_External\Lib\Auth\AuthMechanism; +use \OCA\Files_External\Service\BackendService; +use \OCA\Files_External\Lib\Auth\OpenStack\OpenStack; +use \OCA\Files_External\Lib\Auth\OpenStack\Rackspace; +use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; + +class Swift extends Backend { + + use LegacyDependencyCheckPolyfill; + + public function __construct(IL10N $l, OpenStack $openstackAuth, Rackspace $rackspaceAuth) { + $this + ->setIdentifier('swift') + ->addIdentifierAlias('\OC\Files\Storage\Swift') // legacy compat + ->setStorageClass('\OCA\Files_External\Lib\Storage\Swift') + ->setText($l->t('OpenStack Object Storage')) + ->addParameters([ + (new DefinitionParameter('service_name', $l->t('Service name'))) + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), + (new DefinitionParameter('region', $l->t('Region'))) + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), + (new DefinitionParameter('bucket', $l->t('Bucket'))), + (new DefinitionParameter('timeout', $l->t('Request timeout (seconds)'))) + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), + ]) + ->addAuthScheme(AuthMechanism::SCHEME_OPENSTACK) + ->setLegacyAuthMechanismCallback(function(array $params) use ($openstackAuth, $rackspaceAuth) { + if (isset($params['options']['key']) && $params['options']['key']) { + return $rackspaceAuth; + } + return $openstackAuth; + }) + ; + } + +} diff --git a/apps/files_external/lib/backend/amazons3.php b/apps/files_external/lib/backend/amazons3.php deleted file mode 100644 index 449b6c0379d..00000000000 --- a/apps/files_external/lib/backend/amazons3.php +++ /dev/null @@ -1,61 +0,0 @@ - - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -namespace OCA\Files_External\Lib\Backend; - -use \OCP\IL10N; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Service\BackendService; -use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; - -use \OCA\Files_External\Lib\Auth\AmazonS3\AccessKey; - -class AmazonS3 extends Backend { - - use LegacyDependencyCheckPolyfill; - - public function __construct(IL10N $l, AccessKey $legacyAuth) { - $this - ->setIdentifier('amazons3') - ->addIdentifierAlias('\OC\Files\Storage\AmazonS3') // legacy compat - ->setStorageClass('\OCA\Files_External\Lib\Storage\AmazonS3') - ->setText($l->t('Amazon S3')) - ->addParameters([ - (new DefinitionParameter('bucket', $l->t('Bucket'))), - (new DefinitionParameter('hostname', $l->t('Hostname'))) - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), - (new DefinitionParameter('port', $l->t('Port'))) - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), - (new DefinitionParameter('region', $l->t('Region'))) - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), - (new DefinitionParameter('use_ssl', $l->t('Enable SSL'))) - ->setType(DefinitionParameter::VALUE_BOOLEAN), - (new DefinitionParameter('use_path_style', $l->t('Enable Path Style'))) - ->setType(DefinitionParameter::VALUE_BOOLEAN), - ]) - ->addAuthScheme(AccessKey::SCHEME_AMAZONS3_ACCESSKEY) - ->setLegacyAuthMechanism($legacyAuth) - ; - } - -} diff --git a/apps/files_external/lib/backend/backend.php b/apps/files_external/lib/backend/backend.php deleted file mode 100644 index 8fb84b0e835..00000000000 --- a/apps/files_external/lib/backend/backend.php +++ /dev/null @@ -1,165 +0,0 @@ - - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -namespace OCA\Files_External\Lib\Backend; - -use \OCA\Files_External\Lib\StorageConfig; -use \OCA\Files_External\Lib\VisibilityTrait; -use \OCA\Files_External\Lib\FrontendDefinitionTrait; -use \OCA\Files_External\Lib\PriorityTrait; -use \OCA\Files_External\Lib\DependencyTrait; -use \OCA\Files_External\Lib\StorageModifierTrait; -use \OCA\Files_External\Lib\IdentifierTrait; -use \OCA\Files_External\Lib\Auth\AuthMechanism; - -/** - * Storage backend - * - * A backend can have services injected during construction, - * such as \OCP\IDB for database operations. This allows a backend - * to perform advanced operations based on provided information. - * - * An authenication scheme defines the parameter interface, common to the - * storage implementation, the backend and the authentication mechanism. - * A storage implementation expects parameters according to the authentication - * scheme, which are provided from the authentication mechanism. - * - * This class uses the following traits: - * - VisibilityTrait - * Restrict usage to admin-only/none - * - FrontendDefinitionTrait - * Specify configuration parameters and other definitions - * - PriorityTrait - * Allow objects to prioritize over others with the same mountpoint - * - DependencyTrait - * The object requires certain dependencies to be met - * - StorageModifierTrait - * Object can affect storage mounting - */ -class Backend implements \JsonSerializable { - - use VisibilityTrait; - use FrontendDefinitionTrait; - use PriorityTrait; - use DependencyTrait; - use StorageModifierTrait; - use IdentifierTrait; - - /** @var string storage class */ - private $storageClass; - - /** @var array 'scheme' => true, supported authentication schemes */ - private $authSchemes = []; - - /** @var AuthMechanism|callable authentication mechanism fallback */ - private $legacyAuthMechanism; - - /** - * @return string - */ - public function getStorageClass() { - return $this->storageClass; - } - - /** - * @param string $class - * @return self - */ - public function setStorageClass($class) { - $this->storageClass = $class; - return $this; - } - - /** - * @return array - */ - public function getAuthSchemes() { - if (empty($this->authSchemes)) { - return [AuthMechanism::SCHEME_NULL => true]; - } - return $this->authSchemes; - } - - /** - * @param string $scheme - * @return self - */ - public function addAuthScheme($scheme) { - $this->authSchemes[$scheme] = true; - return $this; - } - - /** - * @param array $parameters storage parameters, for dynamic mechanism selection - * @return AuthMechanism - */ - public function getLegacyAuthMechanism(array $parameters = []) { - if (is_callable($this->legacyAuthMechanism)) { - return call_user_func($this->legacyAuthMechanism, $parameters); - } - return $this->legacyAuthMechanism; - } - - /** - * @param AuthMechanism $authMechanism - * @return self - */ - public function setLegacyAuthMechanism(AuthMechanism $authMechanism) { - $this->legacyAuthMechanism = $authMechanism; - return $this; - } - - /** - * @param callable $callback dynamic auth mechanism selection - * @return self - */ - public function setLegacyAuthMechanismCallback(callable $callback) { - $this->legacyAuthMechanism = $callback; - } - - /** - * Serialize into JSON for client-side JS - * - * @return array - */ - public function jsonSerialize() { - $data = $this->jsonSerializeDefinition(); - $data += $this->jsonSerializeIdentifier(); - - $data['backend'] = $data['name']; // legacy compat - $data['priority'] = $this->getPriority(); - $data['authSchemes'] = $this->getAuthSchemes(); - - return $data; - } - - /** - * Check if parameters are satisfied in a StorageConfig - * - * @param StorageConfig $storage - * @return bool - */ - public function validateStorage(StorageConfig $storage) { - return $this->validateStorageDefinition($storage); - } - -} - diff --git a/apps/files_external/lib/backend/dav.php b/apps/files_external/lib/backend/dav.php deleted file mode 100644 index c6e9630be9e..00000000000 --- a/apps/files_external/lib/backend/dav.php +++ /dev/null @@ -1,55 +0,0 @@ - - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -namespace OCA\Files_External\Lib\Backend; - -use \OCP\IL10N; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Service\BackendService; -use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; - -use \OCA\Files_External\Lib\Auth\Password\Password; - -class DAV extends Backend { - - use LegacyDependencyCheckPolyfill; - - public function __construct(IL10N $l, Password $legacyAuth) { - $this - ->setIdentifier('dav') - ->addIdentifierAlias('\OC\Files\Storage\DAV') // legacy compat - ->setStorageClass('\OC\Files\Storage\DAV') - ->setText($l->t('WebDAV')) - ->addParameters([ - (new DefinitionParameter('host', $l->t('URL'))), - (new DefinitionParameter('root', $l->t('Remote subfolder'))) - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), - (new DefinitionParameter('secure', $l->t('Secure https://'))) - ->setType(DefinitionParameter::VALUE_BOOLEAN), - ]) - ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) - ->setLegacyAuthMechanism($legacyAuth) - ; - } - -} diff --git a/apps/files_external/lib/backend/dropbox.php b/apps/files_external/lib/backend/dropbox.php deleted file mode 100644 index 2133c274996..00000000000 --- a/apps/files_external/lib/backend/dropbox.php +++ /dev/null @@ -1,52 +0,0 @@ - - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -namespace OCA\Files_External\Lib\Backend; - -use \OCP\IL10N; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Service\BackendService; -use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; - -use \OCA\Files_External\Lib\Auth\OAuth1\OAuth1; - -class Dropbox extends Backend { - - use LegacyDependencyCheckPolyfill; - - public function __construct(IL10N $l, OAuth1 $legacyAuth) { - $this - ->setIdentifier('dropbox') - ->addIdentifierAlias('\OC\Files\Storage\Dropbox') // legacy compat - ->setStorageClass('\OCA\Files_External\Lib\Storage\Dropbox') - ->setText($l->t('Dropbox')) - ->addParameters([ - // all parameters handled in OAuth1 mechanism - ]) - ->addAuthScheme(AuthMechanism::SCHEME_OAUTH1) - ->addCustomJs('dropbox') - ->setLegacyAuthMechanism($legacyAuth) - ; - } - -} diff --git a/apps/files_external/lib/backend/ftp.php b/apps/files_external/lib/backend/ftp.php deleted file mode 100644 index 3960592d0bc..00000000000 --- a/apps/files_external/lib/backend/ftp.php +++ /dev/null @@ -1,55 +0,0 @@ - - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -namespace OCA\Files_External\Lib\Backend; - -use \OCP\IL10N; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Service\BackendService; -use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; - -use \OCA\Files_External\Lib\Auth\Password\Password; - -class FTP extends Backend { - - use LegacyDependencyCheckPolyfill; - - public function __construct(IL10N $l, Password $legacyAuth) { - $this - ->setIdentifier('ftp') - ->addIdentifierAlias('\OC\Files\Storage\FTP') // legacy compat - ->setStorageClass('\OCA\Files_External\Lib\Storage\FTP') - ->setText($l->t('FTP')) - ->addParameters([ - (new DefinitionParameter('host', $l->t('Host'))), - (new DefinitionParameter('root', $l->t('Remote subfolder'))) - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), - (new DefinitionParameter('secure', $l->t('Secure ftps://'))) - ->setType(DefinitionParameter::VALUE_BOOLEAN), - ]) - ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) - ->setLegacyAuthMechanism($legacyAuth) - ; - } - -} diff --git a/apps/files_external/lib/backend/google.php b/apps/files_external/lib/backend/google.php deleted file mode 100644 index b18b7bdb348..00000000000 --- a/apps/files_external/lib/backend/google.php +++ /dev/null @@ -1,52 +0,0 @@ - - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -namespace OCA\Files_External\Lib\Backend; - -use \OCP\IL10N; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Service\BackendService; -use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; - -use \OCA\Files_External\Lib\Auth\OAuth2\OAuth2; - -class Google extends Backend { - - use LegacyDependencyCheckPolyfill; - - public function __construct(IL10N $l, OAuth2 $legacyAuth) { - $this - ->setIdentifier('googledrive') - ->addIdentifierAlias('\OC\Files\Storage\Google') // legacy compat - ->setStorageClass('\OCA\Files_External\Lib\Storage\Google') - ->setText($l->t('Google Drive')) - ->addParameters([ - // all parameters handled in OAuth2 mechanism - ]) - ->addAuthScheme(AuthMechanism::SCHEME_OAUTH2) - ->addCustomJs('gdrive') - ->setLegacyAuthMechanism($legacyAuth) - ; - } - -} diff --git a/apps/files_external/lib/backend/legacybackend.php b/apps/files_external/lib/backend/legacybackend.php deleted file mode 100644 index 752c501e1ec..00000000000 --- a/apps/files_external/lib/backend/legacybackend.php +++ /dev/null @@ -1,104 +0,0 @@ - - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -namespace OCA\Files_External\Lib\Backend; - -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\Auth\Builtin; -use \OCA\Files_External\Lib\MissingDependency; -use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; - -/** - * Legacy compatibility for OC_Mount_Config::registerBackend() - */ -class LegacyBackend extends Backend { - - use LegacyDependencyCheckPolyfill { - LegacyDependencyCheckPolyfill::checkDependencies as doCheckDependencies; - } - - /** @var bool */ - protected $hasDependencies = false; - - /** - * @param string $class - * @param array $definition - * @param Builtin $authMechanism - */ - public function __construct($class, array $definition, Builtin $authMechanism) { - $this - ->setIdentifier($class) - ->setStorageClass($class) - ->setText($definition['backend']) - ->addAuthScheme(Builtin::SCHEME_BUILTIN) - ->setLegacyAuthMechanism($authMechanism) - ; - - foreach ($definition['configuration'] as $name => $placeholder) { - $flags = DefinitionParameter::FLAG_NONE; - $type = DefinitionParameter::VALUE_TEXT; - if ($placeholder[0] === '&') { - $flags = DefinitionParameter::FLAG_OPTIONAL; - $placeholder = substr($placeholder, 1); - } - switch ($placeholder[0]) { - case '!': - $type = DefinitionParameter::VALUE_BOOLEAN; - $placeholder = substr($placeholder, 1); - break; - case '*': - $type = DefinitionParameter::VALUE_PASSWORD; - $placeholder = substr($placeholder, 1); - break; - case '#': - $type = DefinitionParameter::VALUE_HIDDEN; - $placeholder = substr($placeholder, 1); - break; - } - $this->addParameter((new DefinitionParameter($name, $placeholder)) - ->setType($type) - ->setFlags($flags) - ); - } - - if (isset($definition['priority'])) { - $this->setPriority($definition['priority']); - } - if (isset($definition['custom'])) { - $this->addCustomJs($definition['custom']); - } - if (isset($definition['has_dependencies']) && $definition['has_dependencies']) { - $this->hasDependencies = true; - } - } - - /** - * @return MissingDependency[] - */ - public function checkDependencies() { - if ($this->hasDependencies) { - return $this->doCheckDependencies(); - } - return []; - } - -} diff --git a/apps/files_external/lib/backend/local.php b/apps/files_external/lib/backend/local.php deleted file mode 100644 index 1db707e7247..00000000000 --- a/apps/files_external/lib/backend/local.php +++ /dev/null @@ -1,49 +0,0 @@ - - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -namespace OCA\Files_External\Lib\Backend; - -use \OCP\IL10N; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Service\BackendService; -use \OCA\Files_External\Lib\Auth\NullMechanism; - -class Local extends Backend { - - public function __construct(IL10N $l, NullMechanism $legacyAuth) { - $this - ->setIdentifier('local') - ->addIdentifierAlias('\OC\Files\Storage\Local') // legacy compat - ->setStorageClass('\OC\Files\Storage\Local') - ->setText($l->t('Local')) - ->addParameters([ - (new DefinitionParameter('datadir', $l->t('Location'))), - ]) - ->setAllowedVisibility(BackendService::VISIBILITY_ADMIN) - ->setPriority(BackendService::PRIORITY_DEFAULT + 50) - ->addAuthScheme(AuthMechanism::SCHEME_NULL) - ->setLegacyAuthMechanism($legacyAuth) - ; - } - -} diff --git a/apps/files_external/lib/backend/owncloud.php b/apps/files_external/lib/backend/owncloud.php deleted file mode 100644 index e92288b1354..00000000000 --- a/apps/files_external/lib/backend/owncloud.php +++ /dev/null @@ -1,52 +0,0 @@ - - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -namespace OCA\Files_External\Lib\Backend; - -use \OCP\IL10N; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Service\BackendService; - -use \OCA\Files_External\Lib\Auth\Password\Password; - -class OwnCloud extends Backend { - - public function __construct(IL10N $l, Password $legacyAuth) { - $this - ->setIdentifier('owncloud') - ->addIdentifierAlias('\OC\Files\Storage\OwnCloud') // legacy compat - ->setStorageClass('\OCA\Files_External\Lib\Storage\OwnCloud') - ->setText($l->t('ownCloud')) - ->addParameters([ - (new DefinitionParameter('host', $l->t('URL'))), - (new DefinitionParameter('root', $l->t('Remote subfolder'))) - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), - (new DefinitionParameter('secure', $l->t('Secure https://'))) - ->setType(DefinitionParameter::VALUE_BOOLEAN), - ]) - ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) - ->setLegacyAuthMechanism($legacyAuth) - ; - } - -} diff --git a/apps/files_external/lib/backend/sftp.php b/apps/files_external/lib/backend/sftp.php deleted file mode 100644 index fa33caeb576..00000000000 --- a/apps/files_external/lib/backend/sftp.php +++ /dev/null @@ -1,51 +0,0 @@ - - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -namespace OCA\Files_External\Lib\Backend; - -use \OCP\IL10N; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Service\BackendService; - -use \OCA\Files_External\Lib\Auth\Password\Password; - -class SFTP extends Backend { - - public function __construct(IL10N $l, Password $legacyAuth) { - $this - ->setIdentifier('sftp') - ->addIdentifierAlias('\OC\Files\Storage\SFTP') // legacy compat - ->setStorageClass('\OCA\Files_External\Lib\Storage\SFTP') - ->setText($l->t('SFTP')) - ->addParameters([ - (new DefinitionParameter('host', $l->t('Host'))), - (new DefinitionParameter('root', $l->t('Root'))) - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), - ]) - ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) - ->addAuthScheme(AuthMechanism::SCHEME_PUBLICKEY) - ->setLegacyAuthMechanism($legacyAuth) - ; - } - -} diff --git a/apps/files_external/lib/backend/sftp_key.php b/apps/files_external/lib/backend/sftp_key.php deleted file mode 100644 index 838cf6c52b2..00000000000 --- a/apps/files_external/lib/backend/sftp_key.php +++ /dev/null @@ -1,50 +0,0 @@ - - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -namespace OCA\Files_External\Lib\Backend; - -use \OCP\IL10N; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Service\BackendService; -use \OCA\Files_External\Lib\Auth\PublicKey\RSA; -use \OCA\Files_External\Lib\Backend\SFTP; - -class SFTP_Key extends Backend { - - public function __construct(IL10N $l, RSA $legacyAuth, SFTP $sftpBackend) { - $this - ->setIdentifier('\OC\Files\Storage\SFTP_Key') - ->setStorageClass('\OCA\Files_External\Lib\Storage\SFTP') - ->setText($l->t('SFTP with secret key login')) - ->addParameters([ - (new DefinitionParameter('host', $l->t('Host'))), - (new DefinitionParameter('root', $l->t('Remote subfolder'))) - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), - ]) - ->addAuthScheme(AuthMechanism::SCHEME_PUBLICKEY) - ->setLegacyAuthMechanism($legacyAuth) - ->deprecateTo($sftpBackend) - ; - } - -} diff --git a/apps/files_external/lib/backend/smb.php b/apps/files_external/lib/backend/smb.php deleted file mode 100644 index 7ea30dd11bd..00000000000 --- a/apps/files_external/lib/backend/smb.php +++ /dev/null @@ -1,69 +0,0 @@ - - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -namespace OCA\Files_External\Lib\Backend; - -use \OCP\IL10N; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Service\BackendService; -use \OCA\Files_External\Lib\StorageConfig; -use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; - -use \OCA\Files_External\Lib\Auth\Password\Password; -use OCP\IUser; - -class SMB extends Backend { - - use LegacyDependencyCheckPolyfill; - - public function __construct(IL10N $l, Password $legacyAuth) { - $this - ->setIdentifier('smb') - ->addIdentifierAlias('\OC\Files\Storage\SMB') // legacy compat - ->setStorageClass('\OCA\Files_External\Lib\Storage\SMB') - ->setText($l->t('SMB / CIFS')) - ->addParameters([ - (new DefinitionParameter('host', $l->t('Host'))), - (new DefinitionParameter('share', $l->t('Share'))), - (new DefinitionParameter('root', $l->t('Remote subfolder'))) - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), - (new DefinitionParameter('domain', $l->t('Domain'))) - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), - ]) - ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) - ->setLegacyAuthMechanism($legacyAuth) - ; - } - - /** - * @param StorageConfig $storage - * @param IUser $user - */ - public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) { - $user = $storage->getBackendOption('user'); - if ($domain = $storage->getBackendOption('domain')) { - $storage->setBackendOption('user', $domain.'\\'.$user); - } - } - -} diff --git a/apps/files_external/lib/backend/smb_oc.php b/apps/files_external/lib/backend/smb_oc.php deleted file mode 100644 index c543a19bdd8..00000000000 --- a/apps/files_external/lib/backend/smb_oc.php +++ /dev/null @@ -1,72 +0,0 @@ - - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -namespace OCA\Files_External\Lib\Backend; - -use \OCP\IL10N; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Service\BackendService; -use \OCA\Files_External\Lib\Auth\Password\SessionCredentials; -use \OCA\Files_External\Lib\StorageConfig; -use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; -use \OCA\Files_External\Lib\Backend\SMB; -use OCP\IUser; - -/** - * Deprecated SMB_OC class - use SMB with the password::sessioncredentials auth mechanism - */ -class SMB_OC extends Backend { - - use LegacyDependencyCheckPolyfill; - - public function __construct(IL10N $l, SessionCredentials $legacyAuth, SMB $smbBackend) { - $this - ->setIdentifier('\OC\Files\Storage\SMB_OC') - ->setStorageClass('\OCA\Files_External\Lib\Storage\SMB') - ->setText($l->t('SMB / CIFS using OC login')) - ->addParameters([ - (new DefinitionParameter('host', $l->t('Host'))), - (new DefinitionParameter('username_as_share', $l->t('Username as share'))) - ->setType(DefinitionParameter::VALUE_BOOLEAN), - (new DefinitionParameter('share', $l->t('Share'))) - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), - (new DefinitionParameter('root', $l->t('Remote subfolder'))) - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), - ]) - ->setPriority(BackendService::PRIORITY_DEFAULT - 10) - ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) - ->setLegacyAuthMechanism($legacyAuth) - ->deprecateTo($smbBackend) - ; - } - - public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) { - $username_as_share = ($storage->getBackendOption('username_as_share') === true); - - if ($username_as_share) { - $share = '/' . $storage->getBackendOption('user'); - $storage->setBackendOption('share', $share); - } - } - -} diff --git a/apps/files_external/lib/backend/swift.php b/apps/files_external/lib/backend/swift.php deleted file mode 100644 index 58677575f52..00000000000 --- a/apps/files_external/lib/backend/swift.php +++ /dev/null @@ -1,62 +0,0 @@ - - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -namespace OCA\Files_External\Lib\Backend; - -use \OCP\IL10N; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Service\BackendService; -use \OCA\Files_External\Lib\Auth\OpenStack\OpenStack; -use \OCA\Files_External\Lib\Auth\OpenStack\Rackspace; -use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; - -class Swift extends Backend { - - use LegacyDependencyCheckPolyfill; - - public function __construct(IL10N $l, OpenStack $openstackAuth, Rackspace $rackspaceAuth) { - $this - ->setIdentifier('swift') - ->addIdentifierAlias('\OC\Files\Storage\Swift') // legacy compat - ->setStorageClass('\OCA\Files_External\Lib\Storage\Swift') - ->setText($l->t('OpenStack Object Storage')) - ->addParameters([ - (new DefinitionParameter('service_name', $l->t('Service name'))) - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), - (new DefinitionParameter('region', $l->t('Region'))) - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), - (new DefinitionParameter('bucket', $l->t('Bucket'))), - (new DefinitionParameter('timeout', $l->t('Request timeout (seconds)'))) - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), - ]) - ->addAuthScheme(AuthMechanism::SCHEME_OPENSTACK) - ->setLegacyAuthMechanismCallback(function(array $params) use ($openstackAuth, $rackspaceAuth) { - if (isset($params['options']['key']) && $params['options']['key']) { - return $rackspaceAuth; - } - return $openstackAuth; - }) - ; - } - -} -- cgit v1.2.3