summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2016-05-24 15:15:59 +0200
committerVincent Petry <pvince81@owncloud.com>2016-05-24 15:15:59 +0200
commite7110c767802f9b8e0c9f845e54b6418f47fe74d (patch)
treebf2679521e3a7d39d7bc47b5452124815386e2f6 /lib
parentf7d102ccc59c8290d7e1caedb9862764bd831eaf (diff)
parentabe338f4335ad4a4f0b6211b032e48f80962292f (diff)
downloadnextcloud-server-e7110c767802f9b8e0c9f845e54b6418f47fe74d.tar.gz
nextcloud-server-e7110c767802f9b8e0c9f845e54b6418f47fe74d.zip
Merge pull request #24760 from owncloud/objectstore_multibucket
Objectstore multibucket
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Files/Mount/ObjectHomeMountProvider.php65
-rw-r--r--lib/private/Files/ObjectStore/Mapper.php52
2 files changed, 115 insertions, 2 deletions
diff --git a/lib/private/Files/Mount/ObjectHomeMountProvider.php b/lib/private/Files/Mount/ObjectHomeMountProvider.php
index c910cf6bd45..f82313879dc 100644
--- a/lib/private/Files/Mount/ObjectHomeMountProvider.php
+++ b/lib/private/Files/Mount/ObjectHomeMountProvider.php
@@ -52,9 +52,27 @@ class ObjectHomeMountProvider implements IHomeMountProvider {
* @return \OCP\Files\Mount\IMountPoint[]
*/
public function getHomeMountForUser(IUser $user, IStorageFactory $loader) {
+
+ $config = $this->getMultiBucketObjectStoreConfig($user);
+ if ($config === null) {
+ $config = $this->getSingleBucketObjectStoreConfig($user);
+ }
+
+ if ($config === null) {
+ return null;
+ }
+
+ return new MountPoint('\OC\Files\ObjectStore\HomeObjectStoreStorage', '/' . $user->getUID(), $config['arguments'], $loader);
+ }
+
+ /**
+ * @param IUser $user
+ * @return array|null
+ */
+ private function getSingleBucketObjectStoreConfig(IUser $user) {
$config = $this->config->getSystemValue('objectstore');
if (!is_array($config)) {
- return null; //fall back to local home provider
+ return null;
}
// sanity checks
@@ -68,6 +86,49 @@ class ObjectHomeMountProvider implements IHomeMountProvider {
// instantiate object store implementation
$config['arguments']['objectstore'] = new $config['class']($config['arguments']);
- return new MountPoint('\OC\Files\ObjectStore\HomeObjectStoreStorage', '/' . $user->getUID(), $config['arguments'], $loader);
+ return $config;
+ }
+
+ /**
+ * @param IUser $user
+ * @return array|null
+ */
+ private function getMultiBucketObjectStoreConfig(IUser $user) {
+ $config = $this->config->getSystemValue('objectstore_multibucket');
+ if (!is_array($config)) {
+ return null;
+ }
+
+ // sanity checks
+ if (empty($config['class'])) {
+ \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR);
+ }
+ if (!isset($config['arguments'])) {
+ $config['arguments'] = [];
+ }
+ $config['arguments']['user'] = $user;
+
+ $bucket = $this->config->getUserValue($user->getUID(), 'homeobjectstore', 'bucket', null);
+
+ if ($bucket === null) {
+ /*
+ * Use any provided bucket argument as prefix
+ * and add the mapping from username => bucket
+ */
+ if (!isset($config['arguments']['bucket'])) {
+ $config['arguments']['bucket'] = '';
+ }
+ $mapper = new \OC\Files\ObjectStore\Mapper($user);
+ $config['arguments']['bucket'] .= $mapper->getBucket();
+
+ $this->config->setUserValue($user->getUID(), 'homeobjectstore', 'bucket', $config['arguments']['bucket']);
+ } else {
+ $config['arguments']['bucket'] = $bucket;
+ }
+
+ // instantiate object store implementation
+ $config['arguments']['objectstore'] = new $config['class']($config['arguments']);
+
+ return $config;
}
}
diff --git a/lib/private/Files/ObjectStore/Mapper.php b/lib/private/Files/ObjectStore/Mapper.php
new file mode 100644
index 00000000000..f0004f1f966
--- /dev/null
+++ b/lib/private/Files/ObjectStore/Mapper.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * @author Roeland Jago Douma <rullzer@owncloud.com>
+ *
+ * @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 <http://www.gnu.org/licenses/>
+ *
+ */
+namespace OC\Files\ObjectStore;
+
+use OCP\IUser;
+
+/**
+ * Class Mapper
+ *
+ * @package OC\Files\ObjectStore
+ *
+ * Map a user to a bucket.
+ */
+class Mapper {
+ /** @var IUser */
+ private $user;
+
+ /**
+ * Mapper constructor.
+ *
+ * @param IUser $user
+ */
+ public function __construct(IUser $user) {
+ $this->user = $user;
+ }
+
+ /**
+ * @return string
+ */
+ public function getBucket() {
+ $hash = md5($this->user->getUID());
+ return substr($hash, 0, 3);
+ }
+} \ No newline at end of file