Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BackendService migration of backends #18245

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
139b8e0
Introduce BackendService for managing external storage backends
Aug 11, 2015
cd4f5d1
Introduce UserGlobalStoragesService
Aug 12, 2015
e87be83
Backend framework for generic authentication mechanisms
Aug 12, 2015
7212c66
Split backend identifiers from the class name
Aug 12, 2015
11c2294
Unit tests for new backend API
Aug 12, 2015
12cf64c
Compatibility shims for OC_Mount_Config
Aug 12, 2015
895f70e
Use app container singleton
Aug 12, 2015
391c505
Propagate auth mechanism/backend failures to filesystem layer
Aug 12, 2015
255ceec
Load custom JS for all backends/auth mechanisms
Aug 11, 2015
7337675
Fix JS unit tests
Aug 14, 2015
af79b31
Implement password authentication mechanisms
Aug 12, 2015
b3ff2fd
Revert "Fix mounting wrapped storages resulting in many-layered wrapp…
Aug 10, 2015
89e86c4
Add on-backend and on-auth-mechanism events to JS
Aug 12, 2015
ae30e80
Migrate Local external storage to new API
Aug 12, 2015
b8d61c9
Migrate AmazonS3 external storage to new API
Aug 12, 2015
29d6d59
Migrate Dropbox external storage to new API
Aug 12, 2015
a2cdc6b
Migrate FTP external storage to new API
Aug 12, 2015
4dfa6f5
Migrate Google external storage to new API
Aug 12, 2015
c9f35f1
Migrate Swift external storage to new API
Aug 12, 2015
7603797
Migrate SMB external storage to new API
Aug 12, 2015
12a4a3f
Migrate SMB_OC external storage to new API
Aug 12, 2015
aa04e89
Migrate DAV external storage to new API
Aug 12, 2015
56eeaf8
Migrate OwnCloud external storage to new API
Aug 12, 2015
b80fe9a
Migrate SFTP external storage to new API
Aug 12, 2015
b9b9f71
Migrate SFTP_Key external storage to new API
Aug 12, 2015
f683a60
AjaxController uses RSA auth mechanism, 2048-bit RSA keys
Aug 10, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
OCP\JSON::callCheck();
$l = \OC::$server->getL10N('files_external');

// FIXME: currently hard-coded to Dropbox OAuth
if (isset($_POST['app_key']) && isset($_POST['app_secret'])) {
$oauth = new Dropbox_OAuth_Curl((string)$_POST['app_key'], (string)$_POST['app_secret']);
if (isset($_POST['step'])) {
Expand All @@ -47,7 +48,7 @@
'request_token_secret' => $token['token_secret'])));
} catch (Exception $exception) {
OCP\JSON::error(array('data' => array('message' =>
$l->t('Fetching request tokens failed. Verify that your Dropbox app key and secret are correct.'))
$l->t('Fetching request tokens failed. Verify that your app key and secret are correct.'))
));
}
break;
Expand All @@ -60,13 +61,13 @@
'access_token_secret' => $token['token_secret']));
} catch (Exception $exception) {
OCP\JSON::error(array('data' => array('message' =>
$l->t('Fetching access tokens failed. Verify that your Dropbox app key and secret are correct.'))
$l->t('Fetching access tokens failed. Verify that your app key and secret are correct.'))
));
}
}
break;
}
}
} else {
OCP\JSON::error(array('data' => array('message' => $l->t('Please provide a valid Dropbox app key and secret.'))));
OCP\JSON::error(array('data' => array('message' => $l->t('Please provide a valid app key and secret.'))));
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
OCP\JSON::callCheck();
$l = \OC::$server->getL10N('files_external');

// FIXME: currently hard-coded to Google Drive
if (isset($_POST['client_id']) && isset($_POST['client_secret']) && isset($_POST['redirect'])) {
$client = new Google_Client();
$client->setClientId((string)$_POST['client_id']);
Expand Down
185 changes: 9 additions & 176 deletions apps/files_external/appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,26 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
$app = new \OCA\Files_external\Appinfo\Application();

$l = \OC::$server->getL10N('files_external');

OC::$CLASSPATH['OC\Files\Storage\StreamWrapper'] = 'files_external/lib/streamwrapper.php';
OC::$CLASSPATH['OC\Files\Storage\FTP'] = 'files_external/lib/ftp.php';
OC::$CLASSPATH['OC\Files\Storage\OwnCloud'] = 'files_external/lib/owncloud.php';
OC::$CLASSPATH['OC\Files\Storage\Google'] = 'files_external/lib/google.php';
OC::$CLASSPATH['OC\Files\Storage\Swift'] = 'files_external/lib/swift.php';
OC::$CLASSPATH['OC\Files\Storage\SMB'] = 'files_external/lib/smb.php';
OC::$CLASSPATH['OC\Files\Storage\SMB_OC'] = 'files_external/lib/smb_oc.php';
OC::$CLASSPATH['OC\Files\Storage\AmazonS3'] = 'files_external/lib/amazons3.php';
OC::$CLASSPATH['OC\Files\Storage\Dropbox'] = 'files_external/lib/dropbox.php';
OC::$CLASSPATH['OC\Files\Storage\SFTP'] = 'files_external/lib/sftp.php';
OC::$CLASSPATH['OC\Files\Storage\SFTP_Key'] = 'files_external/lib/sftp_key.php';
OC::$CLASSPATH['OC_Mount_Config'] = 'files_external/lib/config.php';
OC::$CLASSPATH['OCA\Files\External\Api'] = 'files_external/lib/api.php';

require_once __DIR__ . '/../3rdparty/autoload.php';

$app = new \OCA\Files_external\Appinfo\Application();
$appContainer = $app->getContainer();

$l = \OC::$server->getL10N('files_external');

OCP\App::registerAdmin('files_external', 'settings');
if (OCP\Config::getAppValue('files_external', 'allow_user_mounting', 'yes') == 'yes') {
OCP\App::registerPersonal('files_external', 'personal');
Expand All @@ -63,179 +63,12 @@
"name" => $l->t('External storage')
]);

// Teach OC_Mount_Config about the AppFramework
\OC_Mount_Config::initApp($appContainer);

// connecting hooks
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\Local', [
'backend' => (string)$l->t('Local'),
'priority' => 150,
'configuration' => [
'datadir' => (string)$l->t('Location')
],
]);

OC_Mount_Config::registerBackend('\OC\Files\Storage\AmazonS3', [
'backend' => (string)$l->t('Amazon S3'),
'priority' => 100,
'configuration' => [
'key' => (string)$l->t('Key'),
'secret' => '*'.$l->t('Secret'),
'bucket' => (string)$l->t('Bucket'),
],
'has_dependencies' => true,
]);

OC_Mount_Config::registerBackend('\OC\Files\Storage\AmazonS3', [
'backend' => (string)$l->t('Amazon S3 and compliant'),
'priority' => 100,
'configuration' => [
'key' => (string)$l->t('Access Key'),
'secret' => '*'.$l->t('Secret Key'),
'bucket' => (string)$l->t('Bucket'),
'hostname' => '&'.$l->t('Hostname'),
'port' => '&'.$l->t('Port'),
'region' => '&'.$l->t('Region'),
'use_ssl' => '!'.$l->t('Enable SSL'),
'use_path_style' => '!'.$l->t('Enable Path Style')
],
'has_dependencies' => true,
]);

OC_Mount_Config::registerBackend('\OC\Files\Storage\Dropbox', [
'backend' => 'Dropbox',
'priority' => 100,
'configuration' => [
'configured' => '#configured',
'app_key' => (string)$l->t('App key'),
'app_secret' => '*'.$l->t('App secret'),
'token' => '#token',
'token_secret' => '#token_secret'
],
'custom' => 'dropbox',
'has_dependencies' => true,
]);

OC_Mount_Config::registerBackend('\OC\Files\Storage\FTP', [
'backend' => 'FTP',
'priority' => 100,
'configuration' => [
'host' => (string)$l->t('Host'),
'user' => (string)$l->t('Username'),
'password' => '*'.$l->t('Password'),
'root' => '&'.$l->t('Remote subfolder'),
'secure' => '!'.$l->t('Secure ftps://')
],
'has_dependencies' => true,
]);

OC_Mount_Config::registerBackend('\OC\Files\Storage\Google', [
'backend' => 'Google Drive',
'priority' => 100,
'configuration' => [
'configured' => '#configured',
'client_id' => (string)$l->t('Client ID'),
'client_secret' => '*'.$l->t('Client secret'),
'token' => '#token',
],
'custom' => 'google',
'has_dependencies' => true,
]);


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', [
'backend' => 'SMB / CIFS',
'priority' => 100,
'configuration' => [
'host' => (string)$l->t('Host'),
'user' => (string)$l->t('Username'),
'password' => '*'.$l->t('Password'),
'share' => (string)$l->t('Share'),
'root' => '&'.$l->t('Remote subfolder'),
],
'has_dependencies' => true,
]);

OC_Mount_Config::registerBackend('\OC\Files\Storage\SMB_OC', [
'backend' => (string)$l->t('SMB / CIFS using OC login'),
'priority' => 90,
'configuration' => [
'host' => (string)$l->t('Host'),
'username_as_share' => '!'.$l->t('Username as share'),
'share' => '&'.$l->t('Share'),
'root' => '&'.$l->t('Remote subfolder'),
],
'has_dependencies' => true,
]);
}

OC_Mount_Config::registerBackend('\OC\Files\Storage\DAV', [
'backend' => 'WebDAV',
'priority' => 100,
'configuration' => [
'host' => (string)$l->t('URL'),
'user' => (string)$l->t('Username'),
'password' => '*'.$l->t('Password'),
'root' => '&'.$l->t('Remote subfolder'),
'secure' => '!'.$l->t('Secure https://'),
],
'has_dependencies' => true,
]);

OC_Mount_Config::registerBackend('\OC\Files\Storage\OwnCloud', [
'backend' => 'ownCloud',
'priority' => 100,
'configuration' => [
'host' => (string)$l->t('URL'),
'user' => (string)$l->t('Username'),
'password' => '*'.$l->t('Password'),
'root' => '&'.$l->t('Remote subfolder'),
'secure' => '!'.$l->t('Secure https://'),
],
]);


OC_Mount_Config::registerBackend('\OC\Files\Storage\SFTP', [
'backend' => 'SFTP',
'priority' => 100,
'configuration' => [
'host' => (string)$l->t('Host'),
'user' => (string)$l->t('Username'),
'password' => '*'.$l->t('Password'),
'root' => '&'.$l->t('Remote subfolder'),
],
]);

OC_Mount_Config::registerBackend('\OC\Files\Storage\SFTP_Key', [
'backend' => (string)$l->t('SFTP with secret key login'),
'priority' => 100,
'configuration' => array(
'host' => (string)$l->t('Host'),
'user' => (string)$l->t('Username'),
'public_key' => (string)$l->t('Public key'),
'private_key' => '#private_key',
'root' => '&'.$l->t('Remote subfolder')),
'custom' => 'sftp_key',
]
);
$mountProvider = new \OCA\Files_External\Config\ConfigAdapter();
$mountProvider = $appContainer->query('OCA\Files_External\Config\ConfigAdapter');
\OC::$server->getMountProviderCollection()->registerProvider($mountProvider);
77 changes: 67 additions & 10 deletions apps/files_external/appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* @author Morris Jobke <hey@morrisjobke.de>
* @author Ross Nicoll <jrn@jrn.me.uk>
* @author Vincent Petry <pvince81@owncloud.com>
* @author Robin McCorkell <rmccorkell@owncloud.com>
*
* @copyright Copyright (c) 2015, ownCloud, Inc.
* @license AGPL-3.0
Expand All @@ -23,9 +24,9 @@

namespace OCA\Files_External\AppInfo;

use \OCA\Files_External\Controller\AjaxController;
use \OCP\AppFramework\App;
use \OCP\IContainer;
use \OCA\Files_External\Service\BackendService;

/**
* @package OCA\Files_External\Appinfo
Expand All @@ -34,16 +35,72 @@ class Application extends App {
public function __construct(array $urlParams=array()) {
parent::__construct('files_external', $urlParams);

$this->loadBackends();
$this->loadAuthMechanisms();
}

/**
* Load storage backends provided by this app
*/
protected function loadBackends() {
$container = $this->getContainer();
$service = $container->query('OCA\\Files_External\\Service\\BackendService');

/**
* Controllers
*/
$container->registerService('AjaxController', function (IContainer $c) {
return new AjaxController(
$c->query('AppName'),
$c->query('Request')
);
});
$service->registerBackends([
$container->query('OCA\Files_External\Lib\Backend\Local'),
$container->query('OCA\Files_External\Lib\Backend\AmazonS3'),
$container->query('OCA\Files_External\Lib\Backend\Dropbox'),
$container->query('OCA\Files_External\Lib\Backend\FTP'),
$container->query('OCA\Files_External\Lib\Backend\Google'),
$container->query('OCA\Files_External\Lib\Backend\Swift'),
$container->query('OCA\Files_External\Lib\Backend\DAV'),
$container->query('OCA\Files_External\Lib\Backend\OwnCloud'),
$container->query('OCA\Files_External\Lib\Backend\SFTP'),
$container->query('OCA\Files_External\Lib\Backend\SFTP_Key'),
]);

if (!\OC_Util::runningOnWindows()) {
$service->registerBackends([
$container->query('OCA\Files_External\Lib\Backend\SMB'),
$container->query('OCA\Files_External\Lib\Backend\SMB_OC'),
]);
}
}

/**
* Load authentication mechanisms provided by this app
*/
protected function loadAuthMechanisms() {
$container = $this->getContainer();
$service = $container->query('OCA\\Files_External\\Service\\BackendService');

$service->registerAuthMechanisms([
// AuthMechanism::SCHEME_NULL mechanism
$container->query('OCA\Files_External\Lib\Auth\NullMechanism'),

// AuthMechanism::SCHEME_BUILTIN mechanism
$container->query('OCA\Files_External\Lib\Auth\Builtin'),

// AuthMechanism::SCHEME_PASSWORD mechanisms
$container->query('OCA\Files_External\Lib\Auth\Password\Password'),
$container->query('OCA\Files_External\Lib\Auth\Password\SessionCredentials'),

// AuthMechanism::SCHEME_OAUTH1 mechanisms
$container->query('OCA\Files_External\Lib\Auth\OAuth1\OAuth1'),

// AuthMechanism::SCHEME_OAUTH2 mechanisms
$container->query('OCA\Files_External\Lib\Auth\OAuth2\OAuth2'),

// AuthMechanism::SCHEME_PUBLICKEY mechanisms
$container->query('OCA\Files_External\Lib\Auth\PublicKey\RSA'),

// 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'),
]);
}

}
10 changes: 5 additions & 5 deletions apps/files_external/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@
'routes' => array(
array(
'name' => 'Ajax#getSshKeys',
'url' => '/ajax/sftp_key.php',
'url' => '/ajax/public_key.php',
'verb' => 'POST',
'requirements' => array()
)
)
)
);

$this->create('files_external_dropbox', 'ajax/dropbox.php')
->actionInclude('files_external/ajax/dropbox.php');
$this->create('files_external_google', 'ajax/google.php')
->actionInclude('files_external/ajax/google.php');
$this->create('files_external_oauth1', 'ajax/oauth1.php')
->actionInclude('files_external/ajax/oauth1.php');
$this->create('files_external_oauth2', 'ajax/oauth2.php')
->actionInclude('files_external/ajax/oauth2.php');


$this->create('files_external_list_applicable', '/applicable')
Expand Down
Loading