aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/service
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/service
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/service')
-rw-r--r--apps/files_external/service/backendservice.php40
-rw-r--r--apps/files_external/service/storagesservice.php39
2 files changed, 51 insertions, 28 deletions
diff --git a/apps/files_external/service/backendservice.php b/apps/files_external/service/backendservice.php
index c1abbcf2b7c..bee08ecbd15 100644
--- a/apps/files_external/service/backendservice.php
+++ b/apps/files_external/service/backendservice.php
@@ -83,7 +83,9 @@ class BackendService {
if (!$this->isAllowedUserBackend($backend)) {
$backend->removeVisibility(BackendService::VISIBILITY_PERSONAL);
}
- $this->backends[$backend->getClass()] = $backend;
+ foreach ($backend->getIdentifierAliases() as $alias) {
+ $this->backends[$alias] = $backend;
+ }
}
/**
@@ -103,7 +105,9 @@ class BackendService {
if (!$this->isAllowedAuthMechanism($authMech)) {
$authMech->removeVisibility(BackendService::VISIBILITY_PERSONAL);
}
- $this->authMechanisms[$authMech->getClass()] = $authMech;
+ foreach ($authMech->getIdentifierAliases() as $alias) {
+ $this->authMechanisms[$alias] = $authMech;
+ }
}
/**
@@ -121,7 +125,12 @@ class BackendService {
* @return Backend[]
*/
public function getBackends() {
- return $this->backends;
+ // only return real identifiers, no aliases
+ $backends = [];
+ foreach ($this->backends as $backend) {
+ $backends[$backend->getIdentifier()] = $backend;
+ }
+ return $backends;
}
/**
@@ -160,12 +169,12 @@ class BackendService {
}
/**
- * @param string $class Backend class name
+ * @param string $identifier
* @return Backend|null
*/
- public function getBackend($class) {
- if (isset($this->backends[$class])) {
- return $this->backends[$class];
+ public function getBackend($identifier) {
+ if (isset($this->backends[$identifier])) {
+ return $this->backends[$identifier];
}
return null;
}
@@ -176,7 +185,12 @@ class BackendService {
* @return AuthMechanism[]
*/
public function getAuthMechanisms() {
- return $this->authMechanisms;
+ // only return real identifiers, no aliases
+ $mechanisms = [];
+ foreach ($this->authMechanisms as $mechanism) {
+ $mechanisms[$mechanism->getIdentifier()] = $mechanism;
+ }
+ return $mechanisms;
}
/**
@@ -217,12 +231,12 @@ class BackendService {
/**
- * @param string $class
+ * @param string $identifier
* @return AuthMechanism|null
*/
- public function getAuthMechanism($class) {
- if (isset($this->authMechanisms[$class])) {
- return $this->authMechanisms[$class];
+ public function getAuthMechanism($identifier) {
+ if (isset($this->authMechanisms[$identifier])) {
+ return $this->authMechanisms[$identifier];
}
return null;
}
@@ -242,7 +256,7 @@ class BackendService {
*/
protected function isAllowedUserBackend(Backend $backend) {
if ($this->userMountingAllowed &&
- in_array($backend->getClass(), $this->userMountingBackends)
+ !empty(array_intersect($backend->getIdentifierAliases(), $this->userMountingBackends))
) {
return true;
}
diff --git a/apps/files_external/service/storagesservice.php b/apps/files_external/service/storagesservice.php
index b8a1824ba23..e89af6bc756 100644
--- a/apps/files_external/service/storagesservice.php
+++ b/apps/files_external/service/storagesservice.php
@@ -81,9 +81,9 @@ abstract class StoragesService {
$applicable,
$storageOptions
) {
- $backend = $this->backendService->getBackend($storageOptions['class']);
+ $backend = $this->backendService->getBackend($storageOptions['backend']);
if (!$backend) {
- throw new \UnexpectedValueException('Invalid backend class');
+ throw new \UnexpectedValueException('Invalid backend '.$storageOptions['backend']);
}
$storageConfig->setBackend($backend);
@@ -94,7 +94,7 @@ abstract class StoragesService {
$storageOptions['authMechanism'] = 'null'; // to make error handling easier
}
if (!$authMechanism) {
- throw new \UnexpectedValueException('Invalid authentication mechanism class');
+ throw new \UnexpectedValueException('Invalid authentication mechanism '.$storageOptions['authMechanism']);
}
$storageConfig->setAuthMechanism($authMechanism);
@@ -140,9 +140,10 @@ abstract class StoragesService {
* - $mountPath is the mount point path (where the storage must be mounted)
* - $storageOptions is a map of storage options:
* - "priority": storage priority
- * - "backend": backend class name
+ * - "backend": backend identifier
+ * - "class": LEGACY backend class name
* - "options": backend-specific options
- * - "authMechanism": authentication mechanism class name
+ * - "authMechanism": authentication mechanism identifier
* - "mountOptions": mount-specific options (ex: disable previews, scanner, etc)
*/
@@ -186,6 +187,13 @@ abstract class StoragesService {
// options might be needed for the config hash
$storageOptions['options'] = \OC_Mount_Config::decryptPasswords($storageOptions['options']);
+ if (!isset($storageOptions['backend'])) {
+ $storageOptions['backend'] = $storageOptions['class']; // legacy compat
+ }
+ if (!isset($storageOptions['authMechanism'])) {
+ $storageOptions['authMechanism'] = null; // ensure config hash works
+ }
+
if (isset($storageOptions['id'])) {
$configId = (int)$storageOptions['id'];
if (isset($storages[$configId])) {
@@ -271,8 +279,9 @@ abstract class StoragesService {
$options = [
'id' => $storageConfig->getId(),
- 'class' => $storageConfig->getBackend()->getClass(),
- 'authMechanism' => $storageConfig->getAuthMechanism()->getClass(),
+ 'backend' => $storageConfig->getBackend()->getIdentifier(),
+ //'class' => $storageConfig->getBackend()->getClass(),
+ 'authMechanism' => $storageConfig->getAuthMechanism()->getIdentifier(),
'options' => $storageConfig->getBackendOptions(),
];
@@ -350,8 +359,8 @@ abstract class StoragesService {
* Create a storage from its parameters
*
* @param string $mountPoint storage mount point
- * @param string $backendClass backend class name
- * @param string $authMechanismClass authentication mechanism class
+ * @param string $backendIdentifier backend identifier
+ * @param string $authMechanismIdentifier authentication mechanism identifier
* @param array $backendOptions backend-specific options
* @param array|null $mountOptions mount-specific options
* @param array|null $applicableUsers users for which to mount the storage
@@ -362,21 +371,21 @@ abstract class StoragesService {
*/
public function createStorage(
$mountPoint,
- $backendClass,
- $authMechanismClass,
+ $backendIdentifier,
+ $authMechanismIdentifier,
$backendOptions,
$mountOptions = null,
$applicableUsers = null,
$applicableGroups = null,
$priority = null
) {
- $backend = $this->backendService->getBackend($backendClass);
+ $backend = $this->backendService->getBackend($backendIdentifier);
if (!$backend) {
- throw new \InvalidArgumentException('Unable to get backend for backend class '.$backendClass);
+ throw new \InvalidArgumentException('Unable to get backend for '.$backendIdentifier);
}
- $authMechanism = $this->backendService->getAuthMechanism($authMechanismClass);
+ $authMechanism = $this->backendService->getAuthMechanism($authMechanismIdentifier);
if (!$authMechanism) {
- throw new \InvalidArgumentException('Unable to get authentication mechanism for class '.$authMechanismClass);
+ throw new \InvalidArgumentException('Unable to get authentication mechanism for '.$authMechanismIdentifier);
}
$newStorage = new StorageConfig();
$newStorage->setMountPoint($mountPoint);