diff options
author | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2024-08-16 10:53:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-16 10:53:50 +0200 |
commit | d35c4eb911f2eae21e9a7cd0bad89c60e30fda25 (patch) | |
tree | 5e0e4e11c7ecc2f5eff3a9e7cac60fea9eead12d /apps/files_external/lib/Lib/StorageConfig.php | |
parent | e7cbaf3ee323c9187356300012c8cfb3879b0349 (diff) | |
parent | 75180a629216af6b6d4b69bd53aab6d161e628c5 (diff) | |
download | nextcloud-server-d35c4eb911f2eae21e9a7cd0bad89c60e30fda25.tar.gz nextcloud-server-d35c4eb911f2eae21e9a7cd0bad89c60e30fda25.zip |
Merge branch 'master' into jr-readdir-false-false
Signed-off-by: John Molakvoæ <skjnldsv@users.noreply.github.com>
Diffstat (limited to 'apps/files_external/lib/Lib/StorageConfig.php')
-rw-r--r-- | apps/files_external/lib/Lib/StorageConfig.php | 69 |
1 files changed, 37 insertions, 32 deletions
diff --git a/apps/files_external/lib/Lib/StorageConfig.php b/apps/files_external/lib/Lib/StorageConfig.php index 757f9d35bdb..682516c73ba 100644 --- a/apps/files_external/lib/Lib/StorageConfig.php +++ b/apps/files_external/lib/Lib/StorageConfig.php @@ -1,42 +1,25 @@ <?php /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Jesús Macias <jmacias@solidgear.es> - * @author Joas Schilling <coding@schilljs.com> - * @author Lukas Reschke <lukas@statuscode.ch> - * @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: 2019-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ namespace OCA\Files_External\Lib; use OCA\Files_External\Lib\Auth\AuthMechanism; use OCA\Files_External\Lib\Auth\IUserProvided; use OCA\Files_External\Lib\Backend\Backend; +use OCA\Files_External\ResponseDefinitions; /** * External storage configuration + * + * @psalm-import-type Files_ExternalStorageConfig from ResponseDefinitions */ class StorageConfig implements \JsonSerializable { public const MOUNT_TYPE_ADMIN = 1; + public const MOUNT_TYPE_PERSONAL = 2; + /** @deprecated use MOUNT_TYPE_PERSONAL (full uppercase) instead */ public const MOUNT_TYPE_PERSONAl = 2; /** @@ -63,7 +46,7 @@ class StorageConfig implements \JsonSerializable { /** * Backend options * - * @var array + * @var array<string, mixed> */ private $backendOptions = []; @@ -112,7 +95,7 @@ class StorageConfig implements \JsonSerializable { /** * Mount-specific options * - * @var array + * @var array<string, mixed> */ private $mountOptions = []; @@ -136,7 +119,7 @@ class StorageConfig implements \JsonSerializable { /** * Returns the configuration id * - * @retun int + * @return int */ public function getId() { return $this->id; @@ -381,14 +364,14 @@ class StorageConfig implements \JsonSerializable { } /** - * @return int self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAl + * @return int self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAL */ public function getType() { return $this->type; } /** - * @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAl + * @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAL */ public function setType($type) { $this->type = $type; @@ -396,12 +379,19 @@ class StorageConfig implements \JsonSerializable { /** * Serialize config to JSON + * @return Files_ExternalStorageConfig */ - public function jsonSerialize(): array { + public function jsonSerialize(bool $obfuscate = false): array { $result = []; if (!is_null($this->id)) { $result['id'] = $this->id; } + + // obfuscate sensitive data if requested + if ($obfuscate) { + $this->formatStorageForUI(); + } + $result['mountPoint'] = $this->mountPoint; $result['backend'] = $this->backend->getIdentifier(); $result['authMechanism'] = $this->authMechanism->getIdentifier(); @@ -425,7 +415,22 @@ class StorageConfig implements \JsonSerializable { $result['statusMessage'] = $this->statusMessage; } $result['userProvided'] = $this->authMechanism instanceof IUserProvided; - $result['type'] = ($this->getType() === self::MOUNT_TYPE_PERSONAl) ? 'personal': 'system'; + $result['type'] = ($this->getType() === self::MOUNT_TYPE_PERSONAL) ? 'personal': 'system'; return $result; } + + protected function formatStorageForUI(): void { + /** @var DefinitionParameter[] $parameters */ + $parameters = array_merge($this->getBackend()->getParameters(), $this->getAuthMechanism()->getParameters()); + + $options = $this->getBackendOptions(); + foreach ($options as $key => $value) { + foreach ($parameters as $parameter) { + if ($parameter->getName() === $key && $parameter->getType() === DefinitionParameter::VALUE_PASSWORD) { + $this->setBackendOption($key, DefinitionParameter::UNMODIFIED_PLACEHOLDER); + break; + } + } + } + } } |