示例#1
0
 /**
  * Construct the storage implementation
  *
  * @param StorageConfig $storageConfig
  * @return Storage
  */
 private function constructStorage(StorageConfig $storageConfig)
 {
     $class = $storageConfig->getBackend()->getStorageClass();
     $storage = new $class($storageConfig->getBackendOptions());
     // auth mechanism should fire first
     $storage = $storageConfig->getBackend()->wrapStorage($storage);
     $storage = $storageConfig->getAuthMechanism()->wrapStorage($storage);
     return $storage;
 }
示例#2
0
 /**
  * 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;
 }
示例#3
0
 /**
  * Returns the rusty storage id from oc_storages from the given storage config.
  *
  * @param StorageConfig $storageConfig
  * @return string rusty storage id
  */
 private function getRustyStorageIdFromConfig(StorageConfig $storageConfig)
 {
     // if any of the storage options contains $user, it is not possible
     // to compute the possible storage id as we don't know which users
     // mounted it already (and we certainly don't want to iterate over ALL users)
     foreach ($storageConfig->getBackendOptions() as $value) {
         if (strpos($value, '$user') !== false) {
             throw new \Exception('Cannot compute storage id for deletion due to $user vars in the configuration');
         }
     }
     // note: similar to ConfigAdapter->prepateStorageConfig()
     $storageConfig->getAuthMechanism()->manipulateStorageConfig($storageConfig);
     $storageConfig->getBackend()->manipulateStorageConfig($storageConfig);
     $class = $storageConfig->getBackend()->getStorageClass();
     $storageImpl = new $class($storageConfig->getBackendOptions());
     return $storageImpl->getId();
 }
示例#4
0
 /**
  * Construct the storage implementation
  *
  * @param StorageConfig $storageConfig
  * @return int
  */
 private function getStorageId(StorageConfig $storageConfig)
 {
     try {
         $class = $storageConfig->getBackend()->getStorageClass();
         /** @var \OC\Files\Storage\Storage $storage */
         $storage = new $class($storageConfig->getBackendOptions());
         // auth mechanism should fire first
         $storage = $storageConfig->getBackend()->wrapStorage($storage);
         $storage = $storageConfig->getAuthMechanism()->wrapStorage($storage);
         return $storage->getStorageCache()->getNumericId();
     } catch (\Exception $e) {
         return -1;
     }
 }
示例#5
0
 /**
  * Check whether the given storage is available / valid.
  *
  * Note that this operation can be time consuming depending
  * on whether the remote storage is available or not.
  *
  * @param StorageConfig $storage storage configuration
  */
 protected function updateStorageStatus(StorageConfig &$storage)
 {
     // update status (can be time-consuming)
     $storage->setStatus(\OC_Mount_Config::getBackendStatus($storage->getBackendClass(), $storage->getBackendOptions(), false));
 }
示例#6
0
 /**
  * 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;
 }
 /**
  * Check if parameters are satisfied in a StorageConfig
  *
  * @param StorageConfig $storage
  * @return bool
  */
 public function validateStorageDefinition(StorageConfig $storage)
 {
     $options = $storage->getBackendOptions();
     foreach ($this->getParameters() as $name => $parameter) {
         $value = isset($options[$name]) ? $options[$name] : null;
         if (!$parameter->validateValue($value)) {
             return false;
         }
     }
     return true;
 }