aboutsummaryrefslogtreecommitdiffstats
path: root/core/Command/Encryption
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2020-06-26 14:54:51 +0200
committerJoas Schilling <coding@schilljs.com>2020-06-26 14:54:51 +0200
commitab21d69903c4360cbce59741624b6e765e3bd35f (patch)
tree8bed2d6af0d4bfef3766e356acc570b93eb9feb3 /core/Command/Encryption
parented4afa55c1ccaef140ac310258ad837bf6af9557 (diff)
downloadnextcloud-server-ab21d69903c4360cbce59741624b6e765e3bd35f.tar.gz
nextcloud-server-ab21d69903c4360cbce59741624b6e765e3bd35f.zip
Add return value to all commands
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'core/Command/Encryption')
-rw-r--r--core/Command/Encryption/ChangeKeyStorageRoot.php6
-rw-r--r--core/Command/Encryption/DecryptAll.php10
-rw-r--r--core/Command/Encryption/Disable.php3
-rw-r--r--core/Command/Encryption/Enable.php6
-rw-r--r--core/Command/Encryption/EncryptAll.php6
-rw-r--r--core/Command/Encryption/ListModules.php5
-rw-r--r--core/Command/Encryption/SetDefaultModule.php6
-rw-r--r--core/Command/Encryption/ShowKeyStorageRoot.php3
-rw-r--r--core/Command/Encryption/Status.php3
9 files changed, 32 insertions, 16 deletions
diff --git a/core/Command/Encryption/ChangeKeyStorageRoot.php b/core/Command/Encryption/ChangeKeyStorageRoot.php
index 894b1f664bf..00e0f8fe332 100644
--- a/core/Command/Encryption/ChangeKeyStorageRoot.php
+++ b/core/Command/Encryption/ChangeKeyStorageRoot.php
@@ -84,14 +84,14 @@ class ChangeKeyStorageRoot extends Command {
);
}
- protected function execute(InputInterface $input, OutputInterface $output) {
+ protected function execute(InputInterface $input, OutputInterface $output): int {
$oldRoot = $this->util->getKeyStorageRoot();
$newRoot = $input->getArgument('newRoot');
if ($newRoot === null) {
$question = new ConfirmationQuestion('No storage root given, do you want to reset the key storage root to the default location? (y/n) ', false);
if (!$this->questionHelper->ask($input, $output, $question)) {
- return;
+ return 1;
}
$newRoot = '';
}
@@ -104,7 +104,9 @@ class ChangeKeyStorageRoot extends Command {
$this->util->setKeyStorageRoot($newRoot);
$output->writeln('');
$output->writeln("Key storage root successfully changed to <info>$newRootDescription</info>");
+ return 0;
}
+ return 1;
}
/**
diff --git a/core/Command/Encryption/DecryptAll.php b/core/Command/Encryption/DecryptAll.php
index 14bf74d8120..51dc74d1eb7 100644
--- a/core/Command/Encryption/DecryptAll.php
+++ b/core/Command/Encryption/DecryptAll.php
@@ -125,14 +125,14 @@ class DecryptAll extends Command {
);
}
- protected function execute(InputInterface $input, OutputInterface $output) {
+ protected function execute(InputInterface $input, OutputInterface $output): int {
if (!$input->isInteractive()) {
$output->writeln('Invalid TTY.');
$output->writeln('If you are trying to execute the command in a Docker ');
$output->writeln("container, do not forget to execute 'docker exec' with");
$output->writeln("the '-i' and '-t' options.");
$output->writeln('');
- return;
+ return 1;
}
$isMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false);
@@ -141,7 +141,7 @@ class DecryptAll extends Command {
$output->writeln("in order to load the relevant encryption modules correctly.");
$output->writeln("Your instance will automatically be put to maintenance mode");
$output->writeln("during the actual decryption of the files.");
- return;
+ return 1;
}
try {
@@ -151,7 +151,7 @@ class DecryptAll extends Command {
$output->writeln('done.');
} else {
$output->writeln('Server side encryption not enabled. Nothing to do.');
- return;
+ return 0;
}
$uid = $input->getArgument('user');
@@ -181,11 +181,13 @@ class DecryptAll extends Command {
$this->config->setAppValue('core', 'encryption_enabled', 'yes');
}
$this->resetMaintenanceAndTrashbin();
+ return 0;
} else {
$output->write('Enable server side encryption... ');
$this->config->setAppValue('core', 'encryption_enabled', 'yes');
$output->writeln('done.');
$output->writeln('aborted');
+ return 1;
}
} catch (\Exception $e) {
// enable server side encryption again if something went wrong
diff --git a/core/Command/Encryption/Disable.php b/core/Command/Encryption/Disable.php
index 4d7542f0a0c..c188e6c097b 100644
--- a/core/Command/Encryption/Disable.php
+++ b/core/Command/Encryption/Disable.php
@@ -46,12 +46,13 @@ class Disable extends Command {
;
}
- protected function execute(InputInterface $input, OutputInterface $output) {
+ protected function execute(InputInterface $input, OutputInterface $output): int {
if ($this->config->getAppValue('core', 'encryption_enabled', 'no') !== 'yes') {
$output->writeln('Encryption is already disabled');
} else {
$this->config->setAppValue('core', 'encryption_enabled', 'no');
$output->writeln('<info>Encryption disabled</info>');
}
+ return 0;
}
}
diff --git a/core/Command/Encryption/Enable.php b/core/Command/Encryption/Enable.php
index 2c475ca666a..2de6eb2e0c7 100644
--- a/core/Command/Encryption/Enable.php
+++ b/core/Command/Encryption/Enable.php
@@ -54,7 +54,7 @@ class Enable extends Command {
;
}
- protected function execute(InputInterface $input, OutputInterface $output) {
+ protected function execute(InputInterface $input, OutputInterface $output): int {
if ($this->config->getAppValue('core', 'encryption_enabled', 'no') === 'yes') {
$output->writeln('Encryption is already enabled');
} else {
@@ -66,15 +66,19 @@ class Enable extends Command {
$modules = $this->encryptionManager->getEncryptionModules();
if (empty($modules)) {
$output->writeln('<error>No encryption module is loaded</error>');
+ return 1;
} else {
$defaultModule = $this->config->getAppValue('core', 'default_encryption_module', null);
if ($defaultModule === null) {
$output->writeln('<error>No default module is set</error>');
+ return 1;
} elseif (!isset($modules[$defaultModule])) {
$output->writeln('<error>The current default module does not exist: ' . $defaultModule . '</error>');
+ return 1;
} else {
$output->writeln('Default module: ' . $defaultModule);
}
}
+ return 0;
}
}
diff --git a/core/Command/Encryption/EncryptAll.php b/core/Command/Encryption/EncryptAll.php
index f2e798966ba..0be03fd95b1 100644
--- a/core/Command/Encryption/EncryptAll.php
+++ b/core/Command/Encryption/EncryptAll.php
@@ -106,14 +106,14 @@ class EncryptAll extends Command {
);
}
- protected function execute(InputInterface $input, OutputInterface $output) {
+ protected function execute(InputInterface $input, OutputInterface $output): int {
if (!$input->isInteractive()) {
$output->writeln('Invalid TTY.');
$output->writeln('If you are trying to execute the command in a Docker ');
$output->writeln("container, do not forget to execute 'docker exec' with");
$output->writeln("the '-i' and '-t' options.");
$output->writeln('');
- return;
+ return 1;
}
if ($this->encryptionManager->isEnabled() === false) {
@@ -141,6 +141,8 @@ class EncryptAll extends Command {
$this->resetMaintenanceAndTrashbin();
} else {
$output->writeln('aborted');
+ return 1;
}
+ return 0;
}
}
diff --git a/core/Command/Encryption/ListModules.php b/core/Command/Encryption/ListModules.php
index 812d2542d51..21a8be8057f 100644
--- a/core/Command/Encryption/ListModules.php
+++ b/core/Command/Encryption/ListModules.php
@@ -59,12 +59,12 @@ class ListModules extends Base {
;
}
- protected function execute(InputInterface $input, OutputInterface $output) {
+ protected function execute(InputInterface $input, OutputInterface $output): int {
$isMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false);
if ($isMaintenanceModeEnabled) {
$output->writeln("Maintenance mode must be disabled when listing modules");
$output->writeln("in order to list the relevant encryption modules correctly.");
- return;
+ return 1;
}
$encryptionModules = $this->encryptionManager->getEncryptionModules();
@@ -76,6 +76,7 @@ class ListModules extends Base {
$encModules[$module['id']]['default'] = $module['id'] === $defaultEncryptionModuleId;
}
$this->writeModuleList($input, $output, $encModules);
+ return 0;
}
/**
diff --git a/core/Command/Encryption/SetDefaultModule.php b/core/Command/Encryption/SetDefaultModule.php
index 01c85abdf6e..21c1ba77322 100644
--- a/core/Command/Encryption/SetDefaultModule.php
+++ b/core/Command/Encryption/SetDefaultModule.php
@@ -65,12 +65,12 @@ class SetDefaultModule extends Command {
;
}
- protected function execute(InputInterface $input, OutputInterface $output) {
+ protected function execute(InputInterface $input, OutputInterface $output): int {
$isMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false);
if ($isMaintenanceModeEnabled) {
$output->writeln("Maintenance mode must be disabled when setting default module,");
$output->writeln("in order to load the relevant encryption modules correctly.");
- return;
+ return 1;
}
$moduleId = $input->getArgument('module');
@@ -81,6 +81,8 @@ class SetDefaultModule extends Command {
$output->writeln('<info>Set default module to "' . $moduleId . '"</info>');
} else {
$output->writeln('<error>The specified module "' . $moduleId . '" does not exist</error>');
+ return 1;
}
+ return 0;
}
}
diff --git a/core/Command/Encryption/ShowKeyStorageRoot.php b/core/Command/Encryption/ShowKeyStorageRoot.php
index 8156781e17b..caac043856e 100644
--- a/core/Command/Encryption/ShowKeyStorageRoot.php
+++ b/core/Command/Encryption/ShowKeyStorageRoot.php
@@ -48,11 +48,12 @@ class ShowKeyStorageRoot extends Command {
->setDescription('Show current key storage root');
}
- protected function execute(InputInterface $input, OutputInterface $output) {
+ protected function execute(InputInterface $input, OutputInterface $output): int {
$currentRoot = $this->util->getKeyStorageRoot();
$rootDescription = $currentRoot !== '' ? $currentRoot : 'default storage location (data/)';
$output->writeln("Current key storage root: <info>$rootDescription</info>");
+ return 0;
}
}
diff --git a/core/Command/Encryption/Status.php b/core/Command/Encryption/Status.php
index 70b7aa87768..b7a6f33d7d8 100644
--- a/core/Command/Encryption/Status.php
+++ b/core/Command/Encryption/Status.php
@@ -48,10 +48,11 @@ class Status extends Base {
;
}
- protected function execute(InputInterface $input, OutputInterface $output) {
+ protected function execute(InputInterface $input, OutputInterface $output): int {
$this->writeArrayInOutputFormat($input, $output, [
'enabled' => $this->encryptionManager->isEnabled(),
'defaultModule' => $this->encryptionManager->getDefaultEncryptionModuleId(),
]);
+ return 0;
}
}