|
9 | 9 | namespace OC\Core\Command\Config\System; |
10 | 10 |
|
11 | 11 | use OC\SystemConfig; |
| 12 | +use OCP\IConfig; |
12 | 13 | use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; |
13 | 14 | use Symfony\Component\Console\Input\InputArgument; |
14 | 15 | use Symfony\Component\Console\Input\InputInterface; |
@@ -80,10 +81,41 @@ protected function execute(InputInterface $input, OutputInterface $output): int |
80 | 81 | $this->systemConfig->setValue($configName, $configValue['value']); |
81 | 82 | } |
82 | 83 |
|
83 | | - $output->writeln('<info>System config value ' . implode(' => ', $configNames) . ' set to ' . $configValue['readable-value'] . '</info>'); |
| 84 | + $readableValue = $this->getReadableValue($configNames, $configValue); |
| 85 | + |
| 86 | + $output->writeln('<info>System config value ' . implode(' => ', $configNames) . ' set to ' . $readableValue . '</info>'); |
84 | 87 | return 0; |
85 | 88 | } |
86 | 89 |
|
| 90 | + /** |
| 91 | + * Builds the value to print for the console output, masking it (or the |
| 92 | + * sensitive parts of it) in case the config key is considered sensitive |
| 93 | + * by SystemConfig. |
| 94 | + * |
| 95 | + * @param string[] $configNames |
| 96 | + * @param array{value: mixed, readable-value: string} $configValue |
| 97 | + */ |
| 98 | + protected function getReadableValue(array $configNames, array $configValue): string { |
| 99 | + $filteredValue = $this->systemConfig->getFilteredValue($configNames[0]); |
| 100 | + foreach (array_slice($configNames, 1) as $key) { |
| 101 | + if (!is_array($filteredValue) || !array_key_exists($key, $filteredValue)) { |
| 102 | + // Nothing got filtered along this path |
| 103 | + return $configValue['readable-value']; |
| 104 | + } |
| 105 | + $filteredValue = $filteredValue[$key]; |
| 106 | + } |
| 107 | + |
| 108 | + if ($filteredValue === $configValue['value']) { |
| 109 | + return $configValue['readable-value']; |
| 110 | + } |
| 111 | + |
| 112 | + if ($filteredValue === IConfig::SENSITIVE_VALUE) { |
| 113 | + return IConfig::SENSITIVE_VALUE; |
| 114 | + } |
| 115 | + |
| 116 | + return 'array ' . json_encode($filteredValue); |
| 117 | + } |
| 118 | + |
87 | 119 | /** |
88 | 120 | * @param array $configNames |
89 | 121 | * @param mixed $existingValues |
|
0 commit comments