Add an option to exclude sensitive values (e.g. for reports)

This commit is contained in:
Joas Schilling 2015-04-30 16:14:10 +02:00
parent 6763637773
commit 2f65332014
1 changed files with 34 additions and 4 deletions

View File

@ -26,9 +26,20 @@ use OC\SystemConfig;
use OCP\IAppConfig; use OCP\IAppConfig;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
class ListConfigs extends Base { class ListConfigs extends Base {
/** @var array */
protected $sensitiveValues = [
'dbpassword',
'dbuser',
'mail_smtpname',
'mail_smtppassword',
'passwordsalt',
'secret',
];
/** * @var SystemConfig */ /** * @var SystemConfig */
protected $systemConfig; protected $systemConfig;
@ -55,16 +66,29 @@ class ListConfigs extends Base {
'app', 'app',
InputArgument::OPTIONAL, InputArgument::OPTIONAL,
'Name of the app ("system" to get the config.php values, "all" for all apps and system)', 'Name of the app ("system" to get the config.php values, "all" for all apps and system)',
'system' 'all'
)
->addOption(
'public',
null,
InputOption::VALUE_NONE,
'Use this option when you want to exclude sensitive configs like passwords, salts, ...'
) )
; ;
} }
protected function execute(InputInterface $input, OutputInterface $output) { protected function execute(InputInterface $input, OutputInterface $output) {
$app = $input->getArgument('app'); $app = $input->getArgument('app');
$noSensitiveValues = $input->getOption('public');
if ($noSensitiveValues && !$input->hasParameterOption('--output')) {
// If you post this publicly we prefer the json format
$input->setOption('output', 'json_pretty');
}
switch ($app) { switch ($app) {
case 'system': case 'system':
$configs = $this->getSystemConfigs(); $configs = $this->getSystemConfigs($noSensitiveValues);
break; break;
case 'all': case 'all':
@ -73,7 +97,7 @@ class ListConfigs extends Base {
foreach ($apps as $appName) { foreach ($apps as $appName) {
$configs[$appName] = $this->appConfig->getValues($appName, false); $configs[$appName] = $this->appConfig->getValues($appName, false);
} }
$configs['system'] = $this->getSystemConfigs(); $configs['system'] = $this->getSystemConfigs($noSensitiveValues);
break; break;
default: default:
@ -85,13 +109,19 @@ class ListConfigs extends Base {
/** /**
* Get the system configs * Get the system configs
*
* @param bool $noSensitiveValues
* @return array * @return array
*/ */
protected function getSystemConfigs() { protected function getSystemConfigs($noSensitiveValues) {
$keys = $this->systemConfig->getKeys(); $keys = $this->systemConfig->getKeys();
$configs = []; $configs = [];
foreach ($keys as $key) { foreach ($keys as $key) {
if ($noSensitiveValues && in_array($key, $this->sensitiveValues)) {
continue;
}
$value = $this->systemConfig->getValue($key, new \Exception('Not set')); $value = $this->systemConfig->getValue($key, new \Exception('Not set'));
if (!($value instanceof \Exception)) { if (!($value instanceof \Exception)) {
$configs[$key] = $value; $configs[$key] = $value;