@@ -32,133 +32,133 @@ |
||
| 32 | 32 | use Symfony\Component\Console\Output\OutputInterface; |
| 33 | 33 | |
| 34 | 34 | class ListConfigs extends Base { |
| 35 | - protected $defaultOutputFormat = self::OUTPUT_FORMAT_JSON_PRETTY; |
|
| 36 | - |
|
| 37 | - /** * @var SystemConfig */ |
|
| 38 | - protected $systemConfig; |
|
| 39 | - |
|
| 40 | - /** @var IAppConfig */ |
|
| 41 | - protected $appConfig; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @param SystemConfig $systemConfig |
|
| 45 | - * @param IAppConfig $appConfig |
|
| 46 | - */ |
|
| 47 | - public function __construct(SystemConfig $systemConfig, IAppConfig $appConfig) { |
|
| 48 | - parent::__construct(); |
|
| 49 | - $this->systemConfig = $systemConfig; |
|
| 50 | - $this->appConfig = $appConfig; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - protected function configure() { |
|
| 54 | - parent::configure(); |
|
| 55 | - |
|
| 56 | - $this |
|
| 57 | - ->setName('config:list') |
|
| 58 | - ->setDescription('List all configs') |
|
| 59 | - ->addArgument( |
|
| 60 | - 'app', |
|
| 61 | - InputArgument::OPTIONAL, |
|
| 62 | - 'Name of the app ("system" to get the config.php values, "all" for all apps and system)', |
|
| 63 | - 'all' |
|
| 64 | - ) |
|
| 65 | - ->addOption( |
|
| 66 | - 'private', |
|
| 67 | - null, |
|
| 68 | - InputOption::VALUE_NONE, |
|
| 69 | - 'Use this option when you want to include sensitive configs like passwords, salts, ...' |
|
| 70 | - ) |
|
| 71 | - ; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 75 | - $app = $input->getArgument('app'); |
|
| 76 | - $noSensitiveValues = !$input->getOption('private'); |
|
| 77 | - |
|
| 78 | - if (!is_string($app)) { |
|
| 79 | - $output->writeln('<error>Invalid app value given</error>'); |
|
| 80 | - return 1; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - switch ($app) { |
|
| 84 | - case 'system': |
|
| 85 | - $configs = [ |
|
| 86 | - 'system' => $this->getSystemConfigs($noSensitiveValues), |
|
| 87 | - ]; |
|
| 88 | - break; |
|
| 89 | - |
|
| 90 | - case 'all': |
|
| 91 | - $apps = $this->appConfig->getApps(); |
|
| 92 | - $configs = [ |
|
| 93 | - 'system' => $this->getSystemConfigs($noSensitiveValues), |
|
| 94 | - 'apps' => [], |
|
| 95 | - ]; |
|
| 96 | - foreach ($apps as $appName) { |
|
| 97 | - $configs['apps'][$appName] = $this->getAppConfigs($appName, $noSensitiveValues); |
|
| 98 | - } |
|
| 99 | - break; |
|
| 100 | - |
|
| 101 | - default: |
|
| 102 | - $configs = [ |
|
| 103 | - 'apps' => [ |
|
| 104 | - $app => $this->getAppConfigs($app, $noSensitiveValues), |
|
| 105 | - ], |
|
| 106 | - ]; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - $this->writeArrayInOutputFormat($input, $output, $configs); |
|
| 110 | - return 0; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Get the system configs |
|
| 115 | - * |
|
| 116 | - * @param bool $noSensitiveValues |
|
| 117 | - * @return array |
|
| 118 | - */ |
|
| 119 | - protected function getSystemConfigs($noSensitiveValues) { |
|
| 120 | - $keys = $this->systemConfig->getKeys(); |
|
| 121 | - |
|
| 122 | - $configs = []; |
|
| 123 | - foreach ($keys as $key) { |
|
| 124 | - if ($noSensitiveValues) { |
|
| 125 | - $value = $this->systemConfig->getFilteredValue($key, serialize(null)); |
|
| 126 | - } else { |
|
| 127 | - $value = $this->systemConfig->getValue($key, serialize(null)); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - if ($value !== 'N;') { |
|
| 131 | - $configs[$key] = $value; |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - return $configs; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Get the app configs |
|
| 140 | - * |
|
| 141 | - * @param string $app |
|
| 142 | - * @param bool $noSensitiveValues |
|
| 143 | - * @return array |
|
| 144 | - */ |
|
| 145 | - protected function getAppConfigs($app, $noSensitiveValues) { |
|
| 146 | - if ($noSensitiveValues) { |
|
| 147 | - return $this->appConfig->getFilteredValues($app, false); |
|
| 148 | - } else { |
|
| 149 | - return $this->appConfig->getValues($app, false); |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * @param string $argumentName |
|
| 155 | - * @param CompletionContext $context |
|
| 156 | - * @return string[] |
|
| 157 | - */ |
|
| 158 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
| 159 | - if ($argumentName === 'app') { |
|
| 160 | - return array_merge(['all', 'system'], \OC_App::getAllApps()); |
|
| 161 | - } |
|
| 162 | - return []; |
|
| 163 | - } |
|
| 35 | + protected $defaultOutputFormat = self::OUTPUT_FORMAT_JSON_PRETTY; |
|
| 36 | + |
|
| 37 | + /** * @var SystemConfig */ |
|
| 38 | + protected $systemConfig; |
|
| 39 | + |
|
| 40 | + /** @var IAppConfig */ |
|
| 41 | + protected $appConfig; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @param SystemConfig $systemConfig |
|
| 45 | + * @param IAppConfig $appConfig |
|
| 46 | + */ |
|
| 47 | + public function __construct(SystemConfig $systemConfig, IAppConfig $appConfig) { |
|
| 48 | + parent::__construct(); |
|
| 49 | + $this->systemConfig = $systemConfig; |
|
| 50 | + $this->appConfig = $appConfig; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + protected function configure() { |
|
| 54 | + parent::configure(); |
|
| 55 | + |
|
| 56 | + $this |
|
| 57 | + ->setName('config:list') |
|
| 58 | + ->setDescription('List all configs') |
|
| 59 | + ->addArgument( |
|
| 60 | + 'app', |
|
| 61 | + InputArgument::OPTIONAL, |
|
| 62 | + 'Name of the app ("system" to get the config.php values, "all" for all apps and system)', |
|
| 63 | + 'all' |
|
| 64 | + ) |
|
| 65 | + ->addOption( |
|
| 66 | + 'private', |
|
| 67 | + null, |
|
| 68 | + InputOption::VALUE_NONE, |
|
| 69 | + 'Use this option when you want to include sensitive configs like passwords, salts, ...' |
|
| 70 | + ) |
|
| 71 | + ; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 75 | + $app = $input->getArgument('app'); |
|
| 76 | + $noSensitiveValues = !$input->getOption('private'); |
|
| 77 | + |
|
| 78 | + if (!is_string($app)) { |
|
| 79 | + $output->writeln('<error>Invalid app value given</error>'); |
|
| 80 | + return 1; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + switch ($app) { |
|
| 84 | + case 'system': |
|
| 85 | + $configs = [ |
|
| 86 | + 'system' => $this->getSystemConfigs($noSensitiveValues), |
|
| 87 | + ]; |
|
| 88 | + break; |
|
| 89 | + |
|
| 90 | + case 'all': |
|
| 91 | + $apps = $this->appConfig->getApps(); |
|
| 92 | + $configs = [ |
|
| 93 | + 'system' => $this->getSystemConfigs($noSensitiveValues), |
|
| 94 | + 'apps' => [], |
|
| 95 | + ]; |
|
| 96 | + foreach ($apps as $appName) { |
|
| 97 | + $configs['apps'][$appName] = $this->getAppConfigs($appName, $noSensitiveValues); |
|
| 98 | + } |
|
| 99 | + break; |
|
| 100 | + |
|
| 101 | + default: |
|
| 102 | + $configs = [ |
|
| 103 | + 'apps' => [ |
|
| 104 | + $app => $this->getAppConfigs($app, $noSensitiveValues), |
|
| 105 | + ], |
|
| 106 | + ]; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + $this->writeArrayInOutputFormat($input, $output, $configs); |
|
| 110 | + return 0; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Get the system configs |
|
| 115 | + * |
|
| 116 | + * @param bool $noSensitiveValues |
|
| 117 | + * @return array |
|
| 118 | + */ |
|
| 119 | + protected function getSystemConfigs($noSensitiveValues) { |
|
| 120 | + $keys = $this->systemConfig->getKeys(); |
|
| 121 | + |
|
| 122 | + $configs = []; |
|
| 123 | + foreach ($keys as $key) { |
|
| 124 | + if ($noSensitiveValues) { |
|
| 125 | + $value = $this->systemConfig->getFilteredValue($key, serialize(null)); |
|
| 126 | + } else { |
|
| 127 | + $value = $this->systemConfig->getValue($key, serialize(null)); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + if ($value !== 'N;') { |
|
| 131 | + $configs[$key] = $value; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + return $configs; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Get the app configs |
|
| 140 | + * |
|
| 141 | + * @param string $app |
|
| 142 | + * @param bool $noSensitiveValues |
|
| 143 | + * @return array |
|
| 144 | + */ |
|
| 145 | + protected function getAppConfigs($app, $noSensitiveValues) { |
|
| 146 | + if ($noSensitiveValues) { |
|
| 147 | + return $this->appConfig->getFilteredValues($app, false); |
|
| 148 | + } else { |
|
| 149 | + return $this->appConfig->getValues($app, false); |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * @param string $argumentName |
|
| 155 | + * @param CompletionContext $context |
|
| 156 | + * @return string[] |
|
| 157 | + */ |
|
| 158 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
| 159 | + if ($argumentName === 'app') { |
|
| 160 | + return array_merge(['all', 'system'], \OC_App::getAllApps()); |
|
| 161 | + } |
|
| 162 | + return []; |
|
| 163 | + } |
|
| 164 | 164 | } |