Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

+prepareStorageConfig #128

Merged
merged 1 commit into from
Dec 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions lib/Service/ExternalFolderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@
use OCA\Backup\Model\RestoringPoint;
use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\MountConfig;
use OCA\Files_External\Service\GlobalStoragesService;
use OCP\AppFramework\QueryException;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\GenericFileException;
use OCP\Files\InvalidPathException;
Expand Down Expand Up @@ -816,6 +818,12 @@ public function getStorages(bool $includeUnusedStorage = true): array {

$externals = $this->getAll();
foreach ($this->globalStoragesService->getAllStorages() as $globalStorage) {
try {
$this->prepareStorageConfig($globalStorage);
} catch (Exception $e) {
$this->e($e);
continue;
}
$storage = $this->constructStorage($globalStorage);
$storageId = Storage::getNumericStorageId($storage->getId());

Expand Down Expand Up @@ -864,6 +872,34 @@ public function getStorageById(int $storageId): ExternalFolder {
}


/**
* Process storage ready for mounting
* based on apps/files_external/lib/Config/ConfigAdapter.php
*
* @param StorageConfig $storage
*
* @throws InsufficientDataForMeaningfulAnswerException
* @throws StorageNotAvailableException
* @throws QueryException
*/
private function prepareStorageConfig(StorageConfig &$storage) {
foreach ($storage->getBackendOptions() as $option => $value) {
$storage->setBackendOption($option, MountConfig::substitutePlaceholdersInConfig($value));
}

$objectStore = $storage->getBackendOption('objectstore');
if ($objectStore) {
$objectClass = $objectStore['class'];
if (!is_subclass_of($objectClass, '\OCP\Files\ObjectStore\IObjectStore')) {
throw new \InvalidArgumentException('Invalid object store');
}
$storage->setBackendOption('objectstore', new $objectClass($objectStore));
}

$storage->getAuthMechanism()->manipulateStorageConfig($storage, $user);
$storage->getBackend()->manipulateStorageConfig($storage, $user);
}

/**
* Construct the storage implementation
* based on apps/files_external/lib/Config/ConfigAdapter.php
Expand Down