made name mandatory for apikeys

This commit is contained in:
tracer 2024-04-17 20:28:51 +02:00
parent 17535d825d
commit eaa137291b
3 changed files with 44 additions and 24 deletions

View File

@ -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",

View File

@ -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=<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 <ID> 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 <ID> 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 <ID> 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 <ID> 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;
}
}
}
}

View File

@ -236,6 +236,7 @@ readonly class DomainRepository
}
}
// FIXME check for master/slave in config generation
public function getLongestEntry(string $field): int
{
$sql = "