feat: allow configuring multiple objectstore configurations

Signed-off-by: Robin Appelman <robin@icewind.nl>
pull/52786/head
Robin Appelman 2022-12-01 16:25:15 +07:00
parent 055b5ddb9e
commit 385dd36ff8
2 changed files with 32 additions and 8 deletions

@ -34,9 +34,14 @@ class PrimaryObjectStoreConfig {
* @return ?ObjectStoreConfig
*/
public function getObjectStoreConfigForRoot(): ?array {
$config = $this->getObjectStoreConfig();
$configs = $this->getObjectStoreConfig();
if (!$configs) {
return null;
}
if ($config && $config['arguments']['multibucket']) {
$config = $configs['root'] ?? $configs['default'];
if ($config['arguments']['multibucket']) {
if (!isset($config['arguments']['bucket'])) {
$config['arguments']['bucket'] = '';
}
@ -51,16 +56,27 @@ class PrimaryObjectStoreConfig {
* @return ?ObjectStoreConfig
*/
public function getObjectStoreConfigForUser(IUser $user): ?array {
$config = $this->getObjectStoreConfig();
$configs = $this->getObjectStoreConfig();
if (!$configs) {
return null;
}
$store = $this->config->getUserValue($user->getUID(), 'homeobjectstore', 'objectstore', null);
if ($config && $config['arguments']['multibucket']) {
if ($store) {
$config = $configs[$store];
} else {
$config = $configs['default'];
}
if ($config['arguments']['multibucket']) {
$config['arguments']['bucket'] = $this->getBucketForUser($user, $config);
}
return $config;
}
/**
* @return ?ObjectStoreConfig
* @return ?array<string, ObjectStoreConfig>
*/
private function getObjectStoreConfig(): ?array {
$objectStore = $this->config->getSystemValue('objectstore', null);
@ -69,9 +85,17 @@ class PrimaryObjectStoreConfig {
// new-style multibucket config uses the same 'objectstore' key but sets `'multibucket' => true`, transparently upgrade older style config
if ($objectStoreMultiBucket) {
$objectStoreMultiBucket['arguments']['multibucket'] = true;
return $this->validateObjectStoreConfig($objectStoreMultiBucket);
return [
'default' => $this->validateObjectStoreConfig($objectStoreMultiBucket)
];
} elseif ($objectStore) {
return $this->validateObjectStoreConfig($objectStore);
if (!isset($objectStore['default'])) {
$objectStore = [
'default' => $objectStore,
];
}
return array_map($this->validateObjectStoreConfig(...), $objectStore);
} else {
return null;
}

@ -84,7 +84,7 @@ class ObjectHomeMountProviderTest extends \Test\TestCase {
$this->config->method('getUserValue')
->willReturn(null);
$this->config->expects($this->once())
$this->config
->method('setUserValue')
->with(
$this->equalTo('uid'),