diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-01-04 18:50:09 +0300 |
---|---|---|
committer | blizzz (Rebase PR Action) <blizzz@users.noreply.github.com> | 2022-04-07 23:29:03 +0300 |
commit | c51048b5666e6846fc520154f6248165a2da08ed (patch) | |
tree | d8ad6514bf380e56352d0eda3247aab0bdaed533 /lib/Command | |
parent | 24a632588caa53a8a657ba5a0d01bd7b4941381e (diff) |
Minor fixes
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'lib/Command')
-rw-r--r-- | lib/Command/ConfigDelete.php | 15 | ||||
-rw-r--r-- | lib/Command/ConfigSet.php | 15 |
2 files changed, 28 insertions, 2 deletions
diff --git a/lib/Command/ConfigDelete.php b/lib/Command/ConfigDelete.php index 09310dee..2ccd6ff4 100644 --- a/lib/Command/ConfigDelete.php +++ b/lib/Command/ConfigDelete.php @@ -28,6 +28,7 @@ namespace OCA\User_SAML\Command; use OC\Core\Command\Base; use OCA\User_SAML\SAMLSettings; +use OCP\DB\Exception; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -53,7 +54,19 @@ class ConfigDelete extends Base { protected function execute(InputInterface $input, OutputInterface $output): int { $pId = (int)$input->getArgument('providerId'); - $this->samlSettings->delete($pId); + + if ((string)$pId !== $input->getArgument('providerId')) { + // Make sure we don't delete provider with id 0 by error + $output->writeln('<error>providerId argument needs to be an number. Got: ' . $pId . '</error>'); + return 1; + } + try { + $this->samlSettings->delete($pId); + $output->writeln('Provider deleted.'); + } catch (Exception $e) { + $output->writeln('<error>Provider with id: ' . $providerId . ' does not exist.</error>'); + return 1; + } return 0; } } diff --git a/lib/Command/ConfigSet.php b/lib/Command/ConfigSet.php index 8f55f8bc..1e0a577f 100644 --- a/lib/Command/ConfigSet.php +++ b/lib/Command/ConfigSet.php @@ -28,6 +28,7 @@ namespace OCA\User_SAML\Command; use OC\Core\Command\Base; use OCA\User_SAML\SAMLSettings; +use OCP\DB\Exception; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -65,7 +66,18 @@ class ConfigSet extends Base { protected function execute(InputInterface $input, OutputInterface $output): int { $pId = (int)$input->getArgument('providerId'); - $settings = $this->samlSettings->get($pId); + + if ((string)$pId !== $input->getArgument('providerId')) { + // Make sure we don't delete provider with id 0 by error + $output->writeln('<error>providerId argument needs to be an number. Got: ' . $pId . '</error>'); + return 1; + } + try { + $settings = $this->samlSettings->get($pId); + } catch (Exception $e) { + $output->writeln('<error>Provider with id: ' . $providerId . ' does not exist.</error>'); + return 1; + } foreach ($input->getOptions() as $key => $value) { if (!in_array($key, SAMLSettings::IDP_CONFIG_KEYS) || $value === null) { @@ -78,6 +90,7 @@ class ConfigSet extends Base { $settings[$key] = $value; } $this->samlSettings->set($pId, $settings); + $output->writeln('The provider\'s config was updated.'); return 0; } |