diff options
Diffstat (limited to 'apps/files_external/lib/Command/ListCommand.php')
-rw-r--r-- | apps/files_external/lib/Command/ListCommand.php | 96 |
1 files changed, 29 insertions, 67 deletions
diff --git a/apps/files_external/lib/Command/ListCommand.php b/apps/files_external/lib/Command/ListCommand.php index fadf5d8de27..350916b6c2c 100644 --- a/apps/files_external/lib/Command/ListCommand.php +++ b/apps/files_external/lib/Command/ListCommand.php @@ -1,27 +1,9 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Daniel Kesselberg <mail@danielkesselberg.de> - * @author Joas Schilling <coding@schilljs.com> - * @author Robin Appelman <robin@icewind.nl> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @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: 2017-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ namespace OCA\Files_External\Command; @@ -29,6 +11,7 @@ use OC\Core\Command\Base; use OC\User\NoUserException; use OCA\Files_External\Lib\StorageConfig; use OCA\Files_External\Service\GlobalStoragesService; +use OCA\Files_External\Service\StoragesService; use OCA\Files_External\Service\UserStoragesService; use OCP\IUserManager; use OCP\IUserSession; @@ -39,37 +22,18 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class ListCommand extends Base { - /** - * @var GlobalStoragesService - */ - protected $globalService; - - /** - * @var UserStoragesService - */ - protected $userService; - - /** - * @var IUserSession - */ - protected $userSession; - - /** - * @var IUserManager - */ - protected $userManager; - public const ALL = -1; - public function __construct(GlobalStoragesService $globalService, UserStoragesService $userService, IUserSession $userSession, IUserManager $userManager) { + public function __construct( + protected GlobalStoragesService $globalService, + protected UserStoragesService $userService, + protected IUserSession $userSession, + protected IUserManager $userManager, + ) { parent::__construct(); - $this->globalService = $globalService; - $this->userService = $userService; - $this->userSession = $userSession; - $this->userManager = $userManager; } - protected function configure() { + protected function configure(): void { $this ->setName('files_external:list') ->setDescription('List configured admin or personal mounts') @@ -102,33 +66,31 @@ class ListCommand extends Base { $mounts = $this->globalService->getStorageForAllUsers(); $userId = self::ALL; } else { - $userId = $input->getArgument('user_id'); + $userId = (string)$input->getArgument('user_id'); $storageService = $this->getStorageService($userId); $mounts = $storageService->getAllStorages(); } $this->listMounts($userId, $mounts, $input, $output); - return 0; + return self::SUCCESS; } /** - * @param string $userId + * @param ?string|ListCommand::ALL $userId * @param StorageConfig[] $mounts - * @param InputInterface $input - * @param OutputInterface $output */ - public function listMounts($userId, array $mounts, InputInterface $input, OutputInterface $output) { + public function listMounts($userId, array $mounts, InputInterface $input, OutputInterface $output): void { $outputType = $input->getOption('output'); if (count($mounts) === 0) { if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) { $output->writeln('[]'); } else { if ($userId === self::ALL) { - $output->writeln("<info>No mounts configured</info>"); + $output->writeln('<info>No mounts configured</info>'); } elseif ($userId) { $output->writeln("<info>No mounts configured by $userId</info>"); } else { - $output->writeln("<info>No admin mounts configured</info>"); + $output->writeln('<info>No admin mounts configured</info>'); } } return; @@ -145,12 +107,12 @@ class ListCommand extends Base { } if (!$input->getOption('show-password')) { - $hideKeys = ['password', 'refresh_token', 'token', 'client_secret', 'public_key', 'private_key']; + $hideKeys = ['key', 'bucket', 'secret', 'password', 'refresh_token', 'token', 'client_secret', 'public_key', 'private_key']; foreach ($mounts as $mount) { $config = $mount->getBackendOptions(); foreach ($config as $key => $value) { if (in_array($key, $hideKeys)) { - $mount->setBackendOption($key, '***'); + $mount->setBackendOption($key, '***REMOVED SENSITIVE VALUE***'); } } } @@ -262,16 +224,16 @@ class ListCommand extends Base { } } - protected function getStorageService($userId) { - if (!empty($userId)) { - $user = $this->userManager->get($userId); - if (is_null($user)) { - throw new NoUserException("user $userId not found"); - } - $this->userSession->setUser($user); - return $this->userService; - } else { + protected function getStorageService(string $userId): StoragesService { + if (empty($userId)) { return $this->globalService; } + + $user = $this->userManager->get($userId); + if (is_null($user)) { + throw new NoUserException("user $userId not found"); + } + $this->userSession->setUser($user); + return $this->userService; } } |