ListConfigs.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. *
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OC\Core\Command\Config;
  23. use OC\Core\Command\Base;
  24. use OC\SystemConfig;
  25. use OCP\IAppConfig;
  26. use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
  27. use Symfony\Component\Console\Input\InputArgument;
  28. use Symfony\Component\Console\Input\InputInterface;
  29. use Symfony\Component\Console\Input\InputOption;
  30. use Symfony\Component\Console\Output\OutputInterface;
  31. class ListConfigs extends Base {
  32. protected $defaultOutputFormat = self::OUTPUT_FORMAT_JSON_PRETTY;
  33. /** * @var SystemConfig */
  34. protected $systemConfig;
  35. /** @var IAppConfig */
  36. protected $appConfig;
  37. /**
  38. * @param SystemConfig $systemConfig
  39. * @param IAppConfig $appConfig
  40. */
  41. public function __construct(SystemConfig $systemConfig, IAppConfig $appConfig) {
  42. parent::__construct();
  43. $this->systemConfig = $systemConfig;
  44. $this->appConfig = $appConfig;
  45. }
  46. protected function configure() {
  47. parent::configure();
  48. $this
  49. ->setName('config:list')
  50. ->setDescription('List all configs')
  51. ->addArgument(
  52. 'app',
  53. InputArgument::OPTIONAL,
  54. 'Name of the app ("system" to get the config.php values, "all" for all apps and system)',
  55. 'all'
  56. )
  57. ->addOption(
  58. 'private',
  59. null,
  60. InputOption::VALUE_NONE,
  61. 'Use this option when you want to include sensitive configs like passwords, salts, ...'
  62. )
  63. ;
  64. }
  65. protected function execute(InputInterface $input, OutputInterface $output) {
  66. $app = $input->getArgument('app');
  67. $noSensitiveValues = !$input->getOption('private');
  68. switch ($app) {
  69. case 'system':
  70. $configs = [
  71. 'system' => $this->getSystemConfigs($noSensitiveValues),
  72. ];
  73. break;
  74. case 'all':
  75. $apps = $this->appConfig->getApps();
  76. $configs = [
  77. 'system' => $this->getSystemConfigs($noSensitiveValues),
  78. 'apps' => [],
  79. ];
  80. foreach ($apps as $appName) {
  81. $configs['apps'][$appName] = $this->appConfig->getValues($appName, false);
  82. }
  83. break;
  84. default:
  85. $configs = [
  86. 'apps' => [
  87. $app => $this->appConfig->getValues($app, false),
  88. ],
  89. ];
  90. }
  91. $this->writeArrayInOutputFormat($input, $output, $configs);
  92. }
  93. /**
  94. * Get the system configs
  95. *
  96. * @param bool $noSensitiveValues
  97. * @return array
  98. */
  99. protected function getSystemConfigs($noSensitiveValues) {
  100. $keys = $this->systemConfig->getKeys();
  101. $configs = [];
  102. foreach ($keys as $key) {
  103. if ($noSensitiveValues) {
  104. $value = $this->systemConfig->getFilteredValue($key, serialize(null));
  105. } else {
  106. $value = $this->systemConfig->getValue($key, serialize(null));
  107. }
  108. if ($value !== 'N;') {
  109. $configs[$key] = $value;
  110. }
  111. }
  112. return $configs;
  113. }
  114. /**
  115. * @param string $argumentName
  116. * @param CompletionContext $context
  117. * @return string[]
  118. */
  119. public function completeArgumentValues($argumentName, CompletionContext $context) {
  120. if ($argumentName === 'app') {
  121. return array_merge(['all', 'system'], \OC_App::getAllApps());
  122. }
  123. return [];
  124. }
  125. }