mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Allow multibucket in objectstore
This commit is contained in:
parent
aa56d42fa8
commit
5e2316d05d
2 changed files with 107 additions and 2 deletions
|
|
@ -52,9 +52,27 @@ class ObjectHomeMountProvider implements IHomeMountProvider {
|
|||
* @return \OCP\Files\Mount\IMountPoint[]
|
||||
*/
|
||||
public function getHomeMountForUser(IUser $user, IStorageFactory $loader) {
|
||||
|
||||
$config = $this->multiBucketObjectStore($user);
|
||||
if ($config === null) {
|
||||
$config = $this->singleBucketObjectStore($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 singleBucketObjectStore(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,41 @@ 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 multiBucketObjectStore(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;
|
||||
|
||||
/*
|
||||
* 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();
|
||||
|
||||
// instantiate object store implementation
|
||||
$config['arguments']['objectstore'] = new $config['class']($config['arguments']);
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
52
lib/private/Files/ObjectStore/Mapper.php
Normal file
52
lib/private/Files/ObjectStore/Mapper.php
Normal file
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue