public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) { if (!isset($user)) { throw new InsufficientDataForMeaningfulAnswerException('No credentials saved'); } $uid = $user->getUID(); $credentials = $this->credentialsManager->retrieve($uid, $this->getCredentialsIdentifier($storage->getId())); if (!isset($credentials)) { throw new InsufficientDataForMeaningfulAnswerException('No credentials saved'); } $storage->setBackendOption('user', $credentials['user']); $storage->setBackendOption('password', $credentials['password']); }
/** * Convert a StorageConfig to the legacy mountPoints array format * There's a lot of extra information in here, to satisfy all of the legacy functions * * @param StorageConfig $storage * @param bool $isPersonal * @return array */ private static function prepareMountPointEntry(StorageConfig $storage, $isPersonal) { $mountEntry = []; $mountEntry['mountpoint'] = substr($storage->getMountPoint(), 1); // remove leading slash $mountEntry['class'] = $storage->getBackend()->getIdentifier(); $mountEntry['backend'] = $storage->getBackend()->getText(); $mountEntry['authMechanism'] = $storage->getAuthMechanism()->getIdentifier(); $mountEntry['personal'] = $isPersonal; $mountEntry['options'] = self::decryptPasswords($storage->getBackendOptions()); $mountEntry['mountOptions'] = $storage->getMountOptions(); $mountEntry['priority'] = $storage->getPriority(); $mountEntry['applicable'] = ['groups' => $storage->getApplicableGroups(), 'users' => $storage->getApplicableUsers()]; // if mountpoint is applicable to all users the old API expects ['all'] if (empty($mountEntry['applicable']['groups']) && empty($mountEntry['applicable']['users'])) { $mountEntry['applicable']['users'] = ['all']; } $mountEntry['id'] = $storage->getId(); return $mountEntry; }
/** * Update storage to the configuration * * @param StorageConfig $updatedStorage storage attributes * * @return StorageConfig storage config * @throws NotFoundException if the given storage does not exist in the config */ public function updateStorage(StorageConfig $updatedStorage) { $id = $updatedStorage->getId(); $existingMount = $this->dbConfig->getMountById($id); if (!is_array($existingMount)) { throw new NotFoundException('Storage with id "' . $id . '" not found while updating storage'); } $oldStorage = $this->getStorageConfigFromDBMount($existingMount); $removedUsers = array_diff($oldStorage->getApplicableUsers(), $updatedStorage->getApplicableUsers()); $removedGroups = array_diff($oldStorage->getApplicableGroups(), $updatedStorage->getApplicableGroups()); $addedUsers = array_diff($updatedStorage->getApplicableUsers(), $oldStorage->getApplicableUsers()); $addedGroups = array_diff($updatedStorage->getApplicableGroups(), $oldStorage->getApplicableGroups()); $oldUserCount = count($oldStorage->getApplicableUsers()); $oldGroupCount = count($oldStorage->getApplicableGroups()); $newUserCount = count($oldStorage->getApplicableUsers()); $newGroupCount = count($oldStorage->getApplicableGroups()); $wasGlobal = $oldUserCount + $oldGroupCount === 0; $isGlobal = $newUserCount + $newGroupCount === 0; foreach ($removedUsers as $user) { $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user); } foreach ($removedGroups as $group) { $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group); } foreach ($addedUsers as $user) { $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user); } foreach ($addedGroups as $group) { $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group); } if ($wasGlobal && !$isGlobal) { $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); } else { if (!$wasGlobal && $isGlobal) { $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); } } $changedConfig = array_diff_assoc($updatedStorage->getBackendOptions(), $oldStorage->getBackendOptions()); $changedOptions = array_diff_assoc($updatedStorage->getMountOptions(), $oldStorage->getMountOptions()); foreach ($changedConfig as $key => $value) { $this->dbConfig->setConfig($id, $key, $value); } foreach ($changedOptions as $key => $value) { $this->dbConfig->setOption($id, $key, $value); } $this->triggerChangeHooks($oldStorage, $updatedStorage); return $this->getStorage($id); }
/** * Update storage to the configuration * * @param StorageConfig $updatedStorage storage attributes * * @return StorageConfig storage config * @throws NotFoundException if the given storage does not exist in the config */ public function updateStorage(StorageConfig $updatedStorage) { $allStorages = $this->readConfig(); $id = $updatedStorage->getId(); if (!isset($allStorages[$id])) { throw new NotFoundException('Storage with id "' . $id . '" not found'); } $oldStorage = $allStorages[$id]; // ensure objectstore is persistent if ($objectstore = $oldStorage->getBackendOption('objectstore')) { $updatedStorage->setBackendOption('objectstore', $objectstore); } $allStorages[$id] = $updatedStorage; $this->writeConfig($allStorages); $this->triggerChangeHooks($oldStorage, $updatedStorage); return $this->getStorage($id); }
/** * Update storage to the configuration * * @param StorageConfig $updatedStorage storage attributes * * @return StorageConfig storage config * @throws NotFoundException if the given storage does not exist in the config */ public function updateStorage(StorageConfig $updatedStorage) { $allStorages = $this->readConfig(); $id = $updatedStorage->getId(); if (!isset($allStorages[$id])) { throw new NotFoundException('Storage with id "' . $id . '" not found'); } $oldStorage = $allStorages[$id]; $allStorages[$id] = $updatedStorage; $this->writeConfig($allStorages); $this->triggerChangeHooks($oldStorage, $updatedStorage); return $this->getStorage($id); }
/** * Convert a StorageConfig to the legacy mountPoints array format * There's a lot of extra information in here, to satisfy all of the legacy functions * * @param StorageConfig $storage * @param bool $isPersonal * @return array */ private static function prepareMountPointEntry(StorageConfig $storage, $isPersonal) { $mountEntry = []; $mountEntry['mountpoint'] = substr($storage->getMountPoint(), 1); // remove leading slash $mountEntry['class'] = $storage->getBackend()->getIdentifier(); $mountEntry['backend'] = $storage->getBackend()->getText(); $mountEntry['authMechanism'] = $storage->getAuthMechanism()->getIdentifier(); $mountEntry['personal'] = $isPersonal; $mountEntry['options'] = self::decryptPasswords($storage->getBackendOptions()); $mountEntry['mountOptions'] = $storage->getMountOptions(); $mountEntry['priority'] = $storage->getPriority(); $mountEntry['applicable'] = ['groups' => $storage->getApplicableGroups(), 'users' => $storage->getApplicableUsers()]; $mountEntry['id'] = $storage->getId(); // $mountEntry['storage_id'] = null; // we don't store this! return $mountEntry; }