Migrate Swift external storage to new API

The Rackspace/OpenStack differences have been split into separate auth
mechanisms, with correct legacy migration
This commit is contained in:
Robin McCorkell 2015-08-12 22:10:30 +01:00
parent 59cf326831
commit 19bc5a452a
5 changed files with 159 additions and 18 deletions

View File

@ -70,24 +70,6 @@ if (OCP\Config::getAppValue('files_external', 'allow_user_mounting', 'yes') == '
OCP\Util::connectHook('OC_Filesystem', 'post_initMountPoints', '\OC_Mount_Config', 'initMountPointsHook');
OCP\Util::connectHook('OC_User', 'post_login', 'OC\Files\Storage\SMB_OC', 'login');
OC_Mount_Config::registerBackend('\OC\Files\Storage\Swift', [
'backend' => (string)$l->t('OpenStack Object Storage'),
'priority' => 100,
'configuration' => [
'user' => (string)$l->t('Username'),
'bucket' => (string)$l->t('Bucket'),
'region' => '&'.$l->t('Region (optional for OpenStack Object Storage)'),
'key' => '&*'.$l->t('API Key (required for Rackspace Cloud Files)'),
'tenant' => '&'.$l->t('Tenantname (required for OpenStack Object Storage)'),
'password' => '&*'.$l->t('Password (required for OpenStack Object Storage)'),
'service_name' => '&'.$l->t('Service Name (required for OpenStack Object Storage)'),
'url' => '&'.$l->t('URL of identity endpoint (required for OpenStack Object Storage)'),
'timeout' => '&'.$l->t('Timeout of HTTP requests in seconds'),
],
'has_dependencies' => true,
]);
if (!OC_Util::runningOnWindows()) {
OC_Mount_Config::registerBackend('\OC\Files\Storage\SMB_OC', [
'backend' => (string)$l->t('SMB / CIFS using OC login'),

View File

@ -68,6 +68,7 @@ class Application extends App {
$container->query('OCA\Files_External\Lib\Backend\AmazonS3'),
$container->query('OCA\Files_External\Lib\Backend\Dropbox'),
$container->query('OCA\Files_External\Lib\Backend\Google'),
$container->query('OCA\Files_External\Lib\Backend\Swift'),
]);
if (!\OC_Util::runningOnWindows()) {
@ -101,6 +102,10 @@ class Application extends App {
// AuthMechanism::SCHEME_OAUTH2 mechanisms
$container->query('OCA\Files_External\Lib\Auth\OAuth2\OAuth2'),
// AuthMechanism::SCHEME_OPENSTACK mechanisms
$container->query('OCA\Files_External\Lib\Auth\OpenStack\OpenStack'),
$container->query('OCA\Files_External\Lib\Auth\OpenStack\Rackspace'),
// Specialized mechanisms
$container->query('OCA\Files_External\Lib\Auth\AmazonS3\AccessKey'),
]);

View File

@ -0,0 +1,48 @@
<?php
/**
* @author Robin McCorkell <rmccorkell@owncloud.com>
*
* @copyright Copyright (c) 2015, 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 <http://www.gnu.org/licenses/>
*
*/
namespace OCA\Files_External\Lib\Auth\OpenStack;
use \OCP\IL10N;
use \OCA\Files_External\Lib\DefinitionParameter;
use \OCA\Files_External\Lib\Auth\AuthMechanism;
/**
* OpenStack Keystone authentication
*/
class OpenStack extends AuthMechanism {
public function __construct(IL10N $l) {
$this
->setIdentifier('openstack::openstack')
->setScheme(self::SCHEME_OPENSTACK)
->setText($l->t('OpenStack'))
->addParameters([
(new DefinitionParameter('user', $l->t('Username'))),
(new DefinitionParameter('password', $l->t('Password')))
->setType(DefinitionParameter::VALUE_PASSWORD),
(new DefinitionParameter('tenant', $l->t('Tenant name'))),
(new DefinitionParameter('url', $l->t('Identity endpoint URL'))),
])
;
}
}

View File

@ -0,0 +1,46 @@
<?php
/**
* @author Robin McCorkell <rmccorkell@owncloud.com>
*
* @copyright Copyright (c) 2015, 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 <http://www.gnu.org/licenses/>
*
*/
namespace OCA\Files_External\Lib\Auth\OpenStack;
use \OCP\IL10N;
use \OCA\Files_External\Lib\DefinitionParameter;
use \OCA\Files_External\Lib\Auth\AuthMechanism;
/**
* Rackspace authentication
*/
class Rackspace extends AuthMechanism {
public function __construct(IL10N $l) {
$this
->setIdentifier('openstack::rackspace')
->setScheme(self::SCHEME_OPENSTACK)
->setText($l->t('Rackspace'))
->addParameters([
(new DefinitionParameter('user', $l->t('Username'))),
(new DefinitionParameter('key', $l->t('API key')))
->setType(DefinitionParameter::VALUE_PASSWORD),
])
;
}
}

View File

@ -0,0 +1,60 @@
<?php
/**
* @author Robin McCorkell <rmccorkell@owncloud.com>
*
* @copyright Copyright (c) 2015, 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 <http://www.gnu.org/licenses/>
*
*/
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;
class Swift extends Backend {
public function __construct(IL10N $l, OpenStack $openstackAuth, Rackspace $rackspaceAuth) {
$this
->setIdentifier('swift')
->addIdentifierAlias('\OC\Files\Storage\Swift') // legacy compat
->setStorageClass('\OC\Files\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),
])
->setDependencyCheck('\OC\Files\Storage\Swift::checkDependencies')
->addAuthScheme(AuthMechanism::SCHEME_OPENSTACK)
->setLegacyAuthMechanismCallback(function(array $params) use ($openstackAuth, $rackspaceAuth) {
if (isset($params['key'])) {
return $rackspaceAuth;
}
return $openstackAuth;
})
;
}
}