From eaa137291bab4c71c77df772328783fd8bd06de6 Mon Sep 17 00:00:00 2001 From: tracer Date: Wed, 17 Apr 2024 20:28:51 +0200 Subject: [PATCH] made name mandatory for apikeys --- composer.json | 2 +- src/Controller/CLIController.php | 65 +++++++++++++++++++---------- src/Repository/DomainRepository.php | 1 + 3 files changed, 44 insertions(+), 24 deletions(-) diff --git a/composer.json b/composer.json index c3d351d..d1fe962 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "24unix/bindapi", "description": "manage Bind9 DNS server via REST API", "version": "2023.0.1", - "build_number": "340", + "build_number": "341", "authors": [ { "name": "Micha Espey", diff --git a/src/Controller/CLIController.php b/src/Controller/CLIController.php index fa8fb20..6ea7df1 100644 --- a/src/Controller/CLIController.php +++ b/src/Controller/CLIController.php @@ -76,6 +76,13 @@ class CLIController $this->checkPermissions(); }, description: 'check file permissions')) + ->addCommand(command: new Command( + name: 'panel', + callback: function () { + $this->checkPanel(); + }, + optionalParameters: ['ID', 'fix=xes'], + description: 'Validate setting for this panel')) ->addCommand(command: new Command( name: 'panels', callback: function () { @@ -234,7 +241,7 @@ class CLIController callback: function () { $this->apikeysCreate(); }, - optionalParameters: ['name='])) + mandatoryParameters: ['name'])) ->addCommand(command: new Command( name: 'update', callback: function () { @@ -256,13 +263,6 @@ class CLIController }, description: 'List information about migrations' )) - ->addCommand(command: new Command( - name: 'make', - callback: function () { - $this->migrationsMake(); - }, - description: 'Build a new migration file' - )) ->addCommand(command: new Command( name: 'migrate', callback: function () { @@ -270,6 +270,13 @@ class CLIController }, description: 'Apply a new migration file' )) + ->addCommand(command: new Command( + name: 'make', + callback: function () { + $this->migrationsMake(); + }, + description: '!Use only on dev environments, not in production! Build a new migration file' + )) ); @@ -302,20 +309,6 @@ class CLIController echo COLOR_RED . 'You need to setup the bindAPI permission first.' . COLOR_DEFAULT . PHP_EOL; echo 'Run ' . COLOR_YELLOW . './bin/console check:setup' . COLOR_DEFAULT . ' as root or with sudo.' . PHP_EOL; } - - $self = $this->panelRepository->findSelf(); - - $panelCount = count($self); - - if ($panelCount != 1) { - if ($panelCount == 0) { - echo 'No panel marked as this server.' . PHP_EOL; - echo 'Use ' . COLOR_YELLOW . 'panels:update self=1 ' . COLOR_DEFAULT . 'to mark this panel.' . PHP_EOL; - } else { - echo 'Only one panel can be marked as self.' . PHP_EOL; - echo 'Use ' . COLOR_YELLOW . 'panels:update self=0 ' . COLOR_DEFAULT . 'to remove the stale panel' . PHP_EOL; - } - } } @@ -1127,7 +1120,11 @@ class CLIController */ function apikeysCreate(): void { - $name = $this->arguments['name'] ?? ''; + $name = $this->arguments[1] ?? ''; + if (empty($name)) { + echo 'You need to supply a descriptive name for the apikey.' . PHP_EOL; + exit(1); + } $apiKeyPrefix = uniqid(); try { @@ -2066,4 +2063,26 @@ class CLIController $phinxOutput = new ConsoleOutput(); $returnCode = $command->run(input: new ArrayInput(parameters: $arguments), output: $phinxOutput); } + + private function checkPanel() + { + $self = $this->panelRepository->findSelf(); + + $panelCount = count($self); + + if ($panelCount != 1) { + if ($panelCount == 0) { + echo 'No panel marked as this server.' . PHP_EOL; + echo 'Use ' . COLOR_YELLOW . 'panels:update self=1 ' . COLOR_DEFAULT . 'to mark this panel.' . PHP_EOL; + } else { + echo 'Only one panel can be marked as self.' . PHP_EOL; + echo 'Use ' . COLOR_YELLOW . 'panels:update self=0 ' . COLOR_DEFAULT . 'to remove the stale panel' . PHP_EOL; + } + } else { + if (!$this->quiet) { + echo 'Only one panel is designated as our host' . COLOR_GREEN . ' OK' . COLOR_DEFAULT . PHP_EOL; + } + } + + } } diff --git a/src/Repository/DomainRepository.php b/src/Repository/DomainRepository.php index 2107867..ab85776 100644 --- a/src/Repository/DomainRepository.php +++ b/src/Repository/DomainRepository.php @@ -236,6 +236,7 @@ readonly class DomainRepository } } + // FIXME check for master/slave in config generation public function getLongestEntry(string $field): int { $sql = "