aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib/Config
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external/lib/Config')
-rw-r--r--apps/files_external/lib/Config/ConfigAdapter.php108
-rw-r--r--apps/files_external/lib/Config/ExternalMountPoint.php43
-rw-r--r--apps/files_external/lib/Config/IConfigHandler.php22
-rw-r--r--apps/files_external/lib/Config/SimpleSubstitutionTrait.php24
-rw-r--r--apps/files_external/lib/Config/SystemMountPoint.php23
-rw-r--r--apps/files_external/lib/Config/UserContext.php49
-rw-r--r--apps/files_external/lib/Config/UserPlaceholderHandler.php24
7 files changed, 88 insertions, 205 deletions
diff --git a/apps/files_external/lib/Config/ConfigAdapter.php b/apps/files_external/lib/Config/ConfigAdapter.php
index 7f7c5e3e2eb..a46c0fd5c66 100644
--- a/apps/files_external/lib/Config/ConfigAdapter.php
+++ b/apps/files_external/lib/Config/ConfigAdapter.php
@@ -1,87 +1,71 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Robin McCorkell <robin@mccorkell.me.uk>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Vincent Petry <vincent@nextcloud.com>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Files_External\Config;
+use OC\Files\Cache\Storage;
use OC\Files\Storage\FailedStorage;
use OC\Files\Storage\Wrapper\Availability;
+use OC\Files\Storage\Wrapper\KnownMtime;
use OCA\Files_External\Lib\PersonalMount;
use OCA\Files_External\Lib\StorageConfig;
+use OCA\Files_External\MountConfig;
use OCA\Files_External\Service\UserGlobalStoragesService;
use OCA\Files_External\Service\UserStoragesService;
+use OCP\AppFramework\QueryException;
use OCP\Files\Config\IMountProvider;
-use OCP\Files\Storage;
+use OCP\Files\Mount\IMountPoint;
+use OCP\Files\ObjectStore\IObjectStore;
+use OCP\Files\Storage\IConstructableStorage;
+use OCP\Files\Storage\IStorage;
use OCP\Files\Storage\IStorageFactory;
use OCP\Files\StorageNotAvailableException;
use OCP\IUser;
+use OCP\Server;
+use Psr\Clock\ClockInterface;
+use Psr\Log\LoggerInterface;
/**
* Make the old files_external config work with the new public mount config api
*/
class ConfigAdapter implements IMountProvider {
-
- /** @var UserStoragesService */
- private $userStoragesService;
-
- /** @var UserGlobalStoragesService */
- private $userGlobalStoragesService;
+ public function __construct(
+ private UserStoragesService $userStoragesService,
+ private UserGlobalStoragesService $userGlobalStoragesService,
+ private ClockInterface $clock,
+ ) {
+ }
/**
- * @param UserStoragesService $userStoragesService
- * @param UserGlobalStoragesService $userGlobalStoragesService
+ * @param class-string $class
+ * @return class-string<IObjectStore>
+ * @throws \InvalidArgumentException
+ * @psalm-taint-escape callable
*/
- public function __construct(
- UserStoragesService $userStoragesService,
- UserGlobalStoragesService $userGlobalStoragesService
- ) {
- $this->userStoragesService = $userStoragesService;
- $this->userGlobalStoragesService = $userGlobalStoragesService;
+ private function validateObjectStoreClassString(string $class): string {
+ if (!\is_subclass_of($class, IObjectStore::class)) {
+ throw new \InvalidArgumentException('Invalid object store');
+ }
+ return $class;
}
/**
* Process storage ready for mounting
*
- * @param StorageConfig $storage
- * @param IUser $user
- * @throws \OCP\AppFramework\QueryException
+ * @throws QueryException
*/
- private function prepareStorageConfig(StorageConfig &$storage, IUser $user) {
+ private function prepareStorageConfig(StorageConfig &$storage, IUser $user): void {
foreach ($storage->getBackendOptions() as $option => $value) {
- $storage->setBackendOption($option, \OCA\Files_External\MountConfig::substitutePlaceholdersInConfig($value, $user->getUID()));
+ $storage->setBackendOption($option, MountConfig::substitutePlaceholdersInConfig($value, $user->getUID()));
}
$objectStore = $storage->getBackendOption('objectstore');
if ($objectStore) {
- $objectClass = $objectStore['class'];
- if (!is_subclass_of($objectClass, '\OCP\Files\ObjectStore\IObjectStore')) {
- throw new \InvalidArgumentException('Invalid object store');
- }
+ $objectClass = $this->validateObjectStoreClassString($objectStore['class']);
$storage->setBackendOption('objectstore', new $objectClass($objectStore));
}
@@ -93,10 +77,12 @@ class ConfigAdapter implements IMountProvider {
* Construct the storage implementation
*
* @param StorageConfig $storageConfig
- * @return Storage
*/
- private function constructStorage(StorageConfig $storageConfig) {
+ private function constructStorage(StorageConfig $storageConfig): IStorage {
$class = $storageConfig->getBackend()->getStorageClass();
+ if (!is_a($class, IConstructableStorage::class, true)) {
+ Server::get(LoggerInterface::class)->warning('Building a storage not implementing IConstructableStorage is deprecated since 31.0.0', ['class' => $class]);
+ }
$storage = new $class($storageConfig->getBackendOptions());
// auth mechanism should fire first
@@ -109,9 +95,7 @@ class ConfigAdapter implements IMountProvider {
/**
* Get all mountpoints applicable for the user
*
- * @param \OCP\IUser $user
- * @param \OCP\Files\Storage\IStorageFactory $loader
- * @return \OCP\Files\Mount\IMountPoint[]
+ * @return IMountPoint[]
*/
public function getMountsForUser(IUser $user, IStorageFactory $loader) {
$this->userStoragesService->setUser($user);
@@ -130,11 +114,11 @@ class ConfigAdapter implements IMountProvider {
}, $storageConfigs);
- \OC\Files\Cache\Storage::getGlobalCache()->loadForStorageIds(array_map(function (Storage\IStorage $storage) {
+ Storage::getGlobalCache()->loadForStorageIds(array_map(function (IStorage $storage) {
return $storage->getId();
}, $storages));
- $availableStorages = array_map(function (Storage\IStorage $storage, StorageConfig $storageConfig) {
+ $availableStorages = array_map(function (IStorage $storage, StorageConfig $storageConfig): IStorage {
try {
$availability = $storage->getAvailability();
if (!$availability['available'] && !Availability::shouldRecheck($availability)) {
@@ -149,13 +133,17 @@ class ConfigAdapter implements IMountProvider {
return $storage;
}, $storages, $storageConfigs);
- $mounts = array_map(function (StorageConfig $storageConfig, Storage\IStorage $storage) use ($user, $loader) {
- if ($storageConfig->getType() === StorageConfig::MOUNT_TYPE_PERSONAl) {
+ $mounts = array_map(function (StorageConfig $storageConfig, IStorage $storage) use ($user, $loader) {
+ $storage->setOwner($user->getUID());
+ if ($storageConfig->getType() === StorageConfig::MOUNT_TYPE_PERSONAL) {
return new PersonalMount(
$this->userStoragesService,
$storageConfig,
$storageConfig->getId(),
- $storage,
+ new KnownMtime([
+ 'storage' => $storage,
+ 'clock' => $this->clock,
+ ]),
'/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(),
null,
$loader,
diff --git a/apps/files_external/lib/Config/ExternalMountPoint.php b/apps/files_external/lib/Config/ExternalMountPoint.php
index 090e1c77cdf..97569ed2913 100644
--- a/apps/files_external/lib/Config/ExternalMountPoint.php
+++ b/apps/files_external/lib/Config/ExternalMountPoint.php
@@ -1,43 +1,34 @@
<?php
+
/**
- * @copyright Copyright (c) 2017 Robin Appelman <robin@icewind.nl>
- *
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Robin Appelman <robin@icewind.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_External\Config;
use OC\Files\Mount\MountPoint;
-use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\Lib\Auth\Password\SessionCredentials;
+use OCA\Files_External\Lib\StorageConfig;
class ExternalMountPoint extends MountPoint {
- /** @var StorageConfig */
- protected $storageConfig;
-
- public function __construct(StorageConfig $storageConfig, $storage, $mountpoint, $arguments = null, $loader = null, $mountOptions = null, $mountId = null) {
- $this->storageConfig = $storageConfig;
+ public function __construct(
+ protected StorageConfig $storageConfig,
+ $storage,
+ $mountpoint,
+ $arguments = null,
+ $loader = null,
+ $mountOptions = null,
+ $mountId = null,
+ ) {
parent::__construct($storage, $mountpoint, $arguments, $loader, $mountOptions, $mountId, ConfigAdapter::class);
}
public function getMountType() {
return ($this->storageConfig->getAuthMechanism() instanceof SessionCredentials) ? 'external-session' : 'external';
}
+
+ public function getStorageConfig(): StorageConfig {
+ return $this->storageConfig;
+ }
}
diff --git a/apps/files_external/lib/Config/IConfigHandler.php b/apps/files_external/lib/Config/IConfigHandler.php
index cd7ca4d1050..9e8283cc58b 100644
--- a/apps/files_external/lib/Config/IConfigHandler.php
+++ b/apps/files_external/lib/Config/IConfigHandler.php
@@ -1,24 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_External\Config;
diff --git a/apps/files_external/lib/Config/SimpleSubstitutionTrait.php b/apps/files_external/lib/Config/SimpleSubstitutionTrait.php
index 4f15d285032..85a76054fa8 100644
--- a/apps/files_external/lib/Config/SimpleSubstitutionTrait.php
+++ b/apps/files_external/lib/Config/SimpleSubstitutionTrait.php
@@ -1,26 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Julius Härtl <jus@bitgrid.net>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_External\Config;
diff --git a/apps/files_external/lib/Config/SystemMountPoint.php b/apps/files_external/lib/Config/SystemMountPoint.php
index 7de07699164..af0bf792140 100644
--- a/apps/files_external/lib/Config/SystemMountPoint.php
+++ b/apps/files_external/lib/Config/SystemMountPoint.php
@@ -2,29 +2,14 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2022 Robin Appelman <robin@icewind.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_External\Config;
-
+use OCP\Files\Mount\IShareOwnerlessMount;
use OCP\Files\Mount\ISystemMountPoint;
-class SystemMountPoint extends ExternalMountPoint implements ISystemMountPoint {
+class SystemMountPoint extends ExternalMountPoint implements ISystemMountPoint, IShareOwnerlessMount {
}
diff --git a/apps/files_external/lib/Config/UserContext.php b/apps/files_external/lib/Config/UserContext.php
index a4ff27e42b5..fb5c79a9329 100644
--- a/apps/files_external/lib/Config/UserContext.php
+++ b/apps/files_external/lib/Config/UserContext.php
@@ -1,26 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Julius Härtl <jus@bitgrid.net>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_External\Config;
@@ -33,26 +15,15 @@ use OCP\Share\IManager as ShareManager;
class UserContext {
- /** @var IUserSession */
- private $session;
-
- /** @var ShareManager */
- private $shareManager;
-
- /** @var IRequest */
- private $request;
-
/** @var string */
private $userId;
- /** @var IUserManager */
- private $userManager;
-
- public function __construct(IUserSession $session, ShareManager $manager, IRequest $request, IUserManager $userManager) {
- $this->session = $session;
- $this->shareManager = $manager;
- $this->request = $request;
- $this->userManager = $userManager;
+ public function __construct(
+ private IUserSession $session,
+ private ShareManager $shareManager,
+ private IRequest $request,
+ private IUserManager $userManager,
+ ) {
}
public function getSession(): IUserSession {
@@ -67,7 +38,7 @@ class UserContext {
if ($this->userId !== null) {
return $this->userId;
}
- if ($this->session && $this->session->getUser() !== null) {
+ if ($this->session->getUser() !== null) {
return $this->session->getUser()->getUID();
}
try {
diff --git a/apps/files_external/lib/Config/UserPlaceholderHandler.php b/apps/files_external/lib/Config/UserPlaceholderHandler.php
index b2ced2ecf6a..d158e6923c1 100644
--- a/apps/files_external/lib/Config/UserPlaceholderHandler.php
+++ b/apps/files_external/lib/Config/UserPlaceholderHandler.php
@@ -1,26 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Julius Härtl <jus@bitgrid.net>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_External\Config;