Skip to content

Commit

Permalink
allow configuring multiple objectstore configurations
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Dec 1, 2022
1 parent 7c8a53d commit 6557231
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/private/Files/Mount/ObjectHomeMountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function getHomeMountForUser(IUser $user, IStorageFactory $loader): ?IMou
if ($objectStore === null) {
return null;
}
$arguments = array_merge($this->objectStoreConfig->getObjectStoreArguments(), [
$arguments = array_merge($this->objectStoreConfig->getObjectStoreArgumentsForUser($user), [
'objectstore' => $objectStore,
'user' => $user,
]);
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Mount/RootMountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private function getLocalRootMount(IStorageFactory $loader): MountPoint {
}

private function getObjectStoreRootMount(IStorageFactory $loader, IObjectStore $objectStore): MountPoint {
$arguments = array_merge($this->objectStoreConfig->getObjectStoreArguments(), [
$arguments = array_merge($this->objectStoreConfig->getObjectStoreArgumentsForRoot(), [
'objectstore' => $objectStore,
]);

Expand Down
56 changes: 46 additions & 10 deletions lib/private/Files/ObjectStore/PrimaryObjectStoreConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(IConfig $config, LoggerInterface $logger) {
}

public function getObjectStoreForRoot(): ?IObjectStore {
$config = $this->getObjectStoreConfig();
$config = $this->getObjectStoreConfigForRoot();
if (!$config) {
return null;
}
Expand All @@ -56,43 +56,79 @@ public function getObjectStoreForRoot(): ?IObjectStore {
}

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);
}

// instantiate object store implementation
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);

// 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['default'])) {
$objectStore['default'] = $objectStore;
}
if (!isset($objectStore['multibucket'])) {
$objectStore['multibucket'] = false;

foreach ($objectStore as &$config) {
if (!isset($config['multibucket'])) {
$config['multibucket'] = false;
}

$this->validateObjectStoreConfig($config);
}
$this->validateObjectStoreConfig($objectStore);

return $objectStore;
}

Expand Down

0 comments on commit 6557231

Please sign in to comment.