mirror of https://github.com/nextcloud/server
allow configuring multiple objectstore configurations
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
7c8a53d6c3
commit
d8ed2109cd
|
@ -53,7 +53,7 @@ class ObjectHomeMountProvider implements IHomeMountProvider {
|
|||
if ($objectStore === null) {
|
||||
return null;
|
||||
}
|
||||
$arguments = array_merge($this->objectStoreConfig->getObjectStoreArguments(), [
|
||||
$arguments = array_merge($this->objectStoreConfig->getObjectStoreArgumentsForUser($user), [
|
||||
'objectstore' => $objectStore,
|
||||
'user' => $user,
|
||||
]);
|
||||
|
|
|
@ -57,7 +57,7 @@ class RootMountProvider implements IRootMountProvider {
|
|||
}
|
||||
|
||||
private function getObjectStoreRootMount(IStorageFactory $loader, IObjectStore $objectStore): MountPoint {
|
||||
$arguments = array_merge($this->objectStoreConfig->getObjectStoreArguments(), [
|
||||
$arguments = array_merge($this->objectStoreConfig->getObjectStoreArgumentsForRoot(), [
|
||||
'objectstore' => $objectStore,
|
||||
]);
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ class PrimaryObjectStoreConfig {
|
|||
}
|
||||
|
||||
public function getObjectStoreForRoot(): ?IObjectStore {
|
||||
$config = $this->getObjectStoreConfig();
|
||||
$config = $this->getObjectStoreConfigForRoot();
|
||||
if (!$config) {
|
||||
return null;
|
||||
}
|
||||
|
@ -56,12 +56,12 @@ class PrimaryObjectStoreConfig {
|
|||
}
|
||||
|
||||
public function getObjectStoreForUser(IUser $user): ?IObjectStore {
|
||||
$config = $this->getObjectStoreConfig();
|
||||
$config = $this->getObjectStoreConfigForUser($user);
|
||||
if (!$config) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($config['multibucket']) {
|
||||
if ($config['arguments']['multibucket']) {
|
||||
$config['arguments']['bucket'] = $this->getBucketForUser($user, $config);
|
||||
}
|
||||
|
||||
|
@ -69,14 +69,39 @@ class PrimaryObjectStoreConfig {
|
|||
return new $config['class']($config['arguments']);
|
||||
}
|
||||
|
||||
public function getObjectStoreArguments(): array {
|
||||
$config = $this->getObjectStoreConfig();
|
||||
public function getObjectStoreArgumentsForRoot(): array {
|
||||
$config = $this->getObjectStoreConfigForRoot();
|
||||
if ($config === null) {
|
||||
return [];
|
||||
}
|
||||
return $config['arguments'] ?? [];
|
||||
}
|
||||
|
||||
public function getObjectStoreArgumentsForUser(IUser $user): array {
|
||||
$config = $this->getObjectStoreConfigForUser($user);
|
||||
if ($config === null) {
|
||||
return [];
|
||||
}
|
||||
return $config['arguments'] ?? [];
|
||||
}
|
||||
|
||||
private function getObjectStoreConfigForRoot(): ?array {
|
||||
$configs = $this->getObjectStoreConfig();
|
||||
|
||||
return $configs['root'] ?? $configs['default'];
|
||||
}
|
||||
|
||||
private function getObjectStoreConfigForUser(IUser $user): ?array {
|
||||
$configs = $this->getObjectStoreConfig();
|
||||
$store = $this->config->getUserValue($user->getUID(), 'homeobjectstore', 'objectstore', null);
|
||||
|
||||
if ($store) {
|
||||
return $configs[$store];
|
||||
} else {
|
||||
return $configs['default'];
|
||||
}
|
||||
}
|
||||
|
||||
private function getObjectStoreConfig(): ?array {
|
||||
$objectStore = $this->config->getSystemValue('objectstore', null);
|
||||
$objectStoreMultiBucket = $this->config->getSystemValue('objectstore_multibucket', null);
|
||||
|
@ -84,15 +109,28 @@ class PrimaryObjectStoreConfig {
|
|||
// new-style multibucket config uses the same 'objectstore' key but sets `'multibucket' => true`, transparently upgrade older style config
|
||||
if ($objectStoreMultiBucket) {
|
||||
$objectStoreMultiBucket['multibucket'] = true;
|
||||
$objectStore = $objectStoreMultiBucket;
|
||||
$objectStore = [
|
||||
'default' => $objectStoreMultiBucket,
|
||||
];
|
||||
}
|
||||
if ($objectStore === null) {
|
||||
return null;
|
||||
return ['default' => null];
|
||||
}
|
||||
if (!isset($objectStore['multibucket'])) {
|
||||
$objectStore['multibucket'] = false;
|
||||
|
||||
if (!isset($objectStore['default'])) {
|
||||
$objectStore = [
|
||||
'default' => $objectStore,
|
||||
];
|
||||
}
|
||||
$this->validateObjectStoreConfig($objectStore);
|
||||
|
||||
foreach ($objectStore as &$config) {
|
||||
if (!isset($config['multibucket'])) {
|
||||
$config['multibucket'] = false;
|
||||
}
|
||||
|
||||
$this->validateObjectStoreConfig($config);
|
||||
}
|
||||
|
||||
return $objectStore;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue