Skip to content

Commit

Permalink
Merge pull request #128 from nextcloud/fix/102/prepare-storage
Browse files Browse the repository at this point in the history
+prepareStorageConfig
  • Loading branch information
ArtificialOwl authored Dec 29, 2021
2 parents 069fe25 + 235cd86 commit 7307f1a
Showing 1 changed file with 36 additions and 0 deletions.
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

0 comments on commit 7307f1a

Please sign in to comment.