summaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib
diff options
context:
space:
mode:
authorRobin McCorkell <rmccorkell@owncloud.com>2015-08-12 20:03:11 +0100
committerRobin McCorkell <rmccorkell@owncloud.com>2015-08-19 10:05:11 +0100
commit1eeca031f863a652d07ebfa2f75339232bf60dc1 (patch)
tree2f4b046e3506d4e9e385415bf01961f9b9978d97 /apps/files_external/lib
parent272a46ebe1a5e195a078dde74f5f2ad941923d9e (diff)
downloadnextcloud-server-1eeca031f863a652d07ebfa2f75339232bf60dc1.tar.gz
nextcloud-server-1eeca031f863a652d07ebfa2f75339232bf60dc1.zip
Split backend identifiers from the class name
Prior to this, the storage class name was stored in mount.json under the "class" parameter, and the auth mechanism class name under the "authMechanism" parameter. This decouples the class name from the identifier used to retrieve the backend or auth mechanism. Now, backends/auth mechanisms have a unique identifier, which is saved in the "backend" or "authMechanism" parameter in mount.json respectively. An identifier is considered unique for the object it references, but the underlying class may change (e.g. files_external gets pulled into core and namespaces are modified).
Diffstat (limited to 'apps/files_external/lib')
-rw-r--r--apps/files_external/lib/auth/authmechanism.php9
-rw-r--r--apps/files_external/lib/auth/nullmechanism.php1
-rw-r--r--apps/files_external/lib/backend/backend.php10
-rw-r--r--apps/files_external/lib/config.php41
-rw-r--r--apps/files_external/lib/identifiertrait.php68
-rw-r--r--apps/files_external/lib/storageconfig.php4
6 files changed, 104 insertions, 29 deletions
diff --git a/apps/files_external/lib/auth/authmechanism.php b/apps/files_external/lib/auth/authmechanism.php
index 7da57662db8..a89ee823d51 100644
--- a/apps/files_external/lib/auth/authmechanism.php
+++ b/apps/files_external/lib/auth/authmechanism.php
@@ -23,6 +23,7 @@ namespace OCA\Files_External\Lib\Auth;
use \OCA\Files_External\Lib\StorageConfig;
use \OCA\Files_External\Lib\VisibilityTrait;
+use \OCA\Files_External\Lib\IdentifierTrait;
use \OCA\Files_External\Lib\FrontendDefinitionTrait;
use \OCA\Files_External\Lib\StorageModifierTrait;
@@ -59,18 +60,12 @@ class AuthMechanism implements \JsonSerializable {
use VisibilityTrait;
use FrontendDefinitionTrait;
use StorageModifierTrait;
+ use IdentifierTrait;
/** @var string */
protected $scheme;
/**
- * @return string
- */
- public function getClass() {
- return '\\'.get_class($this);
- }
-
- /**
* Get the authentication scheme implemented
* See self::SCHEME_* constants
*
diff --git a/apps/files_external/lib/auth/nullmechanism.php b/apps/files_external/lib/auth/nullmechanism.php
index 396649d7319..1765fc67396 100644
--- a/apps/files_external/lib/auth/nullmechanism.php
+++ b/apps/files_external/lib/auth/nullmechanism.php
@@ -32,6 +32,7 @@ class NullMechanism extends AuthMechanism {
public function __construct(IL10N $l) {
$this
+ ->setIdentifier('null::null')
->setScheme(self::SCHEME_NULL)
->setText($l->t('None'))
;
diff --git a/apps/files_external/lib/backend/backend.php b/apps/files_external/lib/backend/backend.php
index 634bcb7bfbd..90d5d38ed94 100644
--- a/apps/files_external/lib/backend/backend.php
+++ b/apps/files_external/lib/backend/backend.php
@@ -27,6 +27,7 @@ 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;
/**
@@ -60,6 +61,7 @@ class Backend implements \JsonSerializable {
use PriorityTrait;
use DependencyTrait;
use StorageModifierTrait;
+ use IdentifierTrait;
/** @var string storage class */
private $storageClass;
@@ -73,14 +75,6 @@ class Backend implements \JsonSerializable {
/**
* @return string
*/
- public function getClass() {
- // return storage class for legacy compat
- return $this->getStorageClass();
- }
-
- /**
- * @return string
- */
public function getStorageClass() {
return $this->storageClass;
}
diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php
index e720677480f..c0ded522de0 100644
--- a/apps/files_external/lib/config.php
+++ b/apps/files_external/lib/config.php
@@ -117,14 +117,17 @@ class OC_Mount_Config {
// Global mount points (is this redundant?)
if (isset($mountConfig[self::MOUNT_TYPE_GLOBAL])) {
foreach ($mountConfig[self::MOUNT_TYPE_GLOBAL] as $mountPoint => $options) {
- $backend = $backendService->getBackend($options['class']);
+ if (!isset($options['backend'])) {
+ $options['backend'] = $options['class'];
+ }
+ $backend = $backendService->getBackend($options['backend']);
$options['personal'] = false;
$options['options'] = self::decryptPasswords($options['options']);
if (!isset($options['priority'])) {
$options['priority'] = $backend->getPriority();
}
if (!isset($options['authMechanism'])) {
- $options['authMechanism'] = $backend->getLegacyAuthMechanism($options['options'])->getClass();
+ $options['authMechanism'] = $backend->getLegacyAuthMechanism($options['options'])->getIdentifier();
}
// Override if priority greater
@@ -145,14 +148,17 @@ class OC_Mount_Config {
foreach ($options as &$option) {
$option = self::setUserVars($user, $option);
}
- $backend = $backendService->getBackend($options['class']);
+ if (!isset($options['backend'])) {
+ $options['backend'] = $options['class'];
+ }
+ $backend = $backendService->getBackend($options['backend']);
$options['personal'] = false;
$options['options'] = self::decryptPasswords($options['options']);
if (!isset($options['priority'])) {
$options['priority'] = $backend->getPriority();
}
if (!isset($options['authMechanism'])) {
- $options['authMechanism'] = $backend->getLegacyAuthMechanism($options['options'])->getClass();
+ $options['authMechanism'] = $backend->getLegacyAuthMechanism($options['options'])->getIdentifier();
}
// Override if priority greater
@@ -174,14 +180,17 @@ class OC_Mount_Config {
foreach ($options as &$option) {
$option = self::setUserVars($user, $option);
}
- $backend = $backendService->getBackend($options['class']);
+ if (!isset($options['backend'])) {
+ $options['backend'] = $options['class'];
+ }
+ $backend = $backendService->getBackend($options['backend']);
$options['personal'] = false;
$options['options'] = self::decryptPasswords($options['options']);
if (!isset($options['priority'])) {
$options['priority'] = $backend->getPriority();
}
if (!isset($options['authMechanism'])) {
- $options['authMechanism'] = $backend->getLegacyAuthMechanism($options['options'])->getClass();
+ $options['authMechanism'] = $backend->getLegacyAuthMechanism($options['options'])->getIdentifier();
}
// Override if priority greater or if priority type different
@@ -206,14 +215,17 @@ class OC_Mount_Config {
foreach ($options as &$option) {
$option = self::setUserVars($user, $option);
}
- $backend = $backendService->getBackend($options['class']);
+ if (!isset($options['backend'])) {
+ $options['backend'] = $options['class'];
+ }
+ $backend = $backendService->getBackend($options['backend']);
$options['personal'] = false;
$options['options'] = self::decryptPasswords($options['options']);
if (!isset($options['priority'])) {
$options['priority'] = $backend->getPriority();
}
if (!isset($options['authMechanism'])) {
- $options['authMechanism'] = $backend->getLegacyAuthMechanism($options['options'])->getClass();
+ $options['authMechanism'] = $backend->getLegacyAuthMechanism($options['options'])->getIdentifier();
}
// Override if priority greater or if priority type different
@@ -234,12 +246,15 @@ class OC_Mount_Config {
$mountConfig = self::readData($user);
if (isset($mountConfig[self::MOUNT_TYPE_USER][$user])) {
foreach ($mountConfig[self::MOUNT_TYPE_USER][$user] as $mountPoint => $options) {
- $backend = $backendService->getBackend($options['class']);
+ if (!isset($options['backend'])) {
+ $options['backend'] = $options['class'];
+ }
+ $backend = $backendService->getBackend($options['backend']);
if ($backend->isVisibleFor(BackendService::VISIBILITY_PERSONAL)) {
$options['personal'] = true;
$options['options'] = self::decryptPasswords($options['options']);
if (!isset($options['authMechanism'])) {
- $options['authMechanism'] = $backend->getLegacyAuthMechanism($options['options'])->getClass();
+ $options['authMechanism'] = $backend->getLegacyAuthMechanism($options['options'])->getIdentifier();
}
// Always override previous config
@@ -809,7 +824,8 @@ class OC_Mount_Config {
public static function makeConfigHash($config) {
$data = json_encode(
array(
- 'c' => $config['class'],
+ 'c' => $config['backend'],
+ 'a' => $config['authMechanism'],
'm' => $config['mountpoint'],
'o' => $config['options'],
'p' => isset($config['priority']) ? $config['priority'] : -1,
@@ -858,7 +874,8 @@ class OC_Mount_Config {
return false;
}
- $class = $options['class'];
+ $service = self::$appContainer->query('OCA\Files_External\Service\BackendService');
+ $class = $service->getBackend($options['backend'])->getStorageClass();
try {
/** @var \OC\Files\Storage\Storage $storage */
$storage = new $class($options['options']);
diff --git a/apps/files_external/lib/identifiertrait.php b/apps/files_external/lib/identifiertrait.php
new file mode 100644
index 00000000000..139911580fc
--- /dev/null
+++ b/apps/files_external/lib/identifiertrait.php
@@ -0,0 +1,68 @@
+<?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;
+
+/**
+ * Trait for objects requiring an identifier (and/or identifier aliases)
+ */
+trait IdentifierTrait {
+
+ /** @var string */
+ protected $identifier;
+
+ /** @var string[] */
+ protected $identifierAliases = [];
+
+ /**
+ * @return string
+ */
+ public function getIdentifier() {
+ return $this->identifier;
+ }
+
+ /**
+ * @param string $identifier
+ * @return self
+ */
+ public function setIdentifier($identifier) {
+ $this->identifier = $identifier;
+ $this->identifierAliases[] = $identifier;
+ return $this;
+ }
+
+ /**
+ * @return string[]
+ */
+ public function getIdentifierAliases() {
+ return $this->identifierAliases;
+ }
+
+ /**
+ * @param string $alias
+ * @return self
+ */
+ public function addIdentifierAlias($alias) {
+ $this->identifierAliases[] = $alias;
+ return $this;
+ }
+
+}
diff --git a/apps/files_external/lib/storageconfig.php b/apps/files_external/lib/storageconfig.php
index 96ba2f72ae6..aeb8f527078 100644
--- a/apps/files_external/lib/storageconfig.php
+++ b/apps/files_external/lib/storageconfig.php
@@ -322,8 +322,8 @@ class StorageConfig implements \JsonSerializable {
$result['id'] = $this->id;
}
$result['mountPoint'] = $this->mountPoint;
- $result['backendClass'] = $this->backend->getClass();
- $result['authMechanismClass'] = $this->authMechanism->getClass();
+ $result['backend'] = $this->backend->getIdentifier();
+ $result['authMechanism'] = $this->authMechanism->getIdentifier();
$result['backendOptions'] = $this->backendOptions;
if (!is_null($this->priority)) {
$result['priority'] = $this->priority;