refactored command groups, migrations:make only available in dev/test

This commit is contained in:
tracer 2024-05-03 19:15:19 +02:00
parent bb1a16988d
commit 17e70f14a2
2 changed files with 251 additions and 236 deletions

View File

@ -1,8 +1,8 @@
{
"name": "24unix/bindapi",
"description": "manage Bind9 DNS server via REST API",
"name": "tracer/bindapi",
"description": "manage Bind9 client zones for KeyHelp",
"version": "1.0.9",
"build_number": "375",
"build_number": "376",
"authors": [
{
"name": "Micha Espey",

View File

@ -63,14 +63,12 @@ class CLIController
{
$this->baseDir = dirname(path: __DIR__, levels: 2) . '/';
$this->commandGroupContainer = (new CommandGroupContainer())
->addCommandGroup(commandGroup: (new CommandGroup(name: 'apikeys', description: 'API keys to access this bindAPI'))
$apikeyGroup = (new CommandGroup(name: 'apikeys', description: 'API keys to access this bindAPI'))
->addCommand(command: new Command(
name: 'list',
callback: function () {
$this->apikeysList();
}
)
})
)
->addCommand(command: new Command(
name: 'create',
@ -91,14 +89,120 @@ class CLIController
callback: function () {
$this->apikeysDelete();
},
mandatoryParameters: ['ID'])))
->addCommandGroup(commandGroup: (new CommandGroup(name: 'cron', description: 'Run zone file maintenance'))
mandatoryParameters: ['ID']
));
$cronGroup = (new CommandGroup(name: 'cron', description: 'Run zone file maintenance'))
->addCommand(command: new Command(
name: 'run',
callback: function () {
$this->cronRun();
})))
->addCommandGroup(commandGroup: (new CommandGroup(name: 'check', description: 'health checks the system can perform'))
}));
$panelsGroup = (new CommandGroup(name: 'panels', description: 'all KeyHelp systems configured'))
->addCommand(command: new Command(
name: 'list',
callback: function () {
$this->panelsList();
}))
->addCommand(command: new Command(
name: 'create',
callback: function () {
$this->panelsCreate();
},
mandatoryParameters: ['name'],
optionalParameters: ['A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>', 'self=<yes|no>']))
->addCommand(command: new Command(
name: 'update',
callback: function () {
$this->panelsUpdate();
},
mandatoryParameters: ['ID'],
optionalParameters: ['name=<name>', 'A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>', 'self=<yes|no>']))
->addCommand(command: new Command(
name: 'delete',
callback: function () {
$this->panelsDelete();
},
mandatoryParameters: ['ID']))
->addCommand(command: new Command(
name: 'apiping',
callback: function () {
$this->apiPing(type: 'panel');
},
optionalParameters: ['ID']));
$domainsGroup = (new CommandGroup(name: 'domains', description: 'configured domains'))
->addCommand(command: new Command(
name: 'list',
callback: function () {
$this->domainsList();
}))
->addCommand(command: new Command(
name: 'update',
callback: function () {
$this->domainsUpdate();
},
// mandatoryParameters: ['name'],
// optionalParameters: ['A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>'])))
description: 'Update zone files'));
$nameserversGroup = (new CommandGroup(name: 'nameservers', description: 'available nameservers'))
->addCommand(command: new Command(
name: 'list',
callback: function () {
$this->nameserversList();
}))
->addCommand(command: new Command(
name: 'create',
callback: function () {
$this->nameserversCreate();
},
mandatoryParameters: ['name'],
optionalParameters: ['A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>']))
->addCommand(command: new Command(
name: 'update',
callback: function () {
$this->nameserversUpdate();
},
mandatoryParameters: ['ID'],
optionalParameters: ['name=<name>', 'A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>']))
->addCommand(command: new Command(
name: 'delete',
callback: function () {
$this->nameserversDelete();
},
mandatoryParameters: ['ID']))
->addCommand(command: new Command(
name: 'apiping',
callback: function () {
$this->apiPing(type: 'nameserver');
},
optionalParameters: ['ID']));
$dyndnsGroup = (new CommandGroup(name: 'dyndns', description: 'handle DynDNS entries'))
->addCommand(command: new Command(
name: 'list',
callback: function () {
$this->dynDnsList();
}))
->addCommand(command: new Command(
name: 'create',
callback: function () {
$this->dynDnsCreate();
},
mandatoryParameters: ['hostname.example.com', 'password'],
optionalParameters: ['A=<IPv4>', 'AAAA=<IPv6>'],
description: 'FQDN within a domain where this server is master'))
->addCommand(command: new Command(
name: 'update',
callback: function () {
$this->dynDnyUpdate();
},
mandatoryParameters: ['hostname.example.com',],
optionalParameters: ['password=<password>', 'A=<IPv4>', 'AAAA=<IPv6>']))
->addCommand(command: new Command(
name: 'delete',
callback: function () {
$this->dynDnsDelete();
},
mandatoryParameters: ['ID']));
$checkGroup = (new CommandGroup(name: 'check', description: 'health checks the system can perform'))
->addCommand(command: new Command(
name: 'cache',
callback: function () {
@ -170,113 +274,8 @@ class CLIController
$this->checkVersion();
},
optionalParameters: ['update'],
description: 'Read or set the bindApi version in the database')))
->addCommandGroup(commandGroup: (new CommandGroup(name: 'panels', description: 'all KeyHelp systems configured'))
->addCommand(command: new Command(
name: 'list',
callback: function () {
$this->panelsList();
}))
->addCommand(command: new Command(
name: 'create',
callback: function () {
$this->panelsCreate();
},
mandatoryParameters: ['name'],
optionalParameters: ['A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>', 'self=<yes|no>']))
->addCommand(command: new Command(
name: 'update',
callback: function () {
$this->panelsUpdate();
},
mandatoryParameters: ['ID'],
optionalParameters: ['name=<name>', 'A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>', 'self=<yes|no>']))
->addCommand(command: new Command(
name: 'delete',
callback: function () {
$this->panelsDelete();
},
mandatoryParameters: ['ID']))
->addCommand(command: new Command(
name: 'apiping',
callback: function () {
$this->apiPing(type: 'panel');
},
optionalParameters: ['ID'])))
->addCommandGroup(commandGroup: (new CommandGroup(name: 'nameservers', description: 'available nameservers'))
->addCommand(command: new Command(
name: 'list',
callback: function () {
$this->nameserversList();
}))
->addCommand(command: new Command(
name: 'create',
callback: function () {
$this->nameserversCreate();
},
mandatoryParameters: ['name'],
optionalParameters: ['A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>']))
->addCommand(command: new Command(
name: 'update',
callback: function () {
$this->nameserversUpdate();
},
mandatoryParameters: ['ID'],
optionalParameters: ['name=<name>', 'A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>']))
->addCommand(command: new Command(
name: 'delete',
callback: function () {
$this->nameserversDelete();
},
mandatoryParameters: ['ID']))
->addCommand(command: new Command(
name: 'apiping',
callback: function () {
$this->apiPing(type: 'nameserver');
},
optionalParameters: ['ID'])))
->addCommandGroup(commandGroup: (new CommandGroup(name: 'domains', description: 'configured domains'))
->addCommand(command: new Command(
name: 'list',
callback: function () {
$this->domainsList();
}))
->addCommand(command: new Command(
name: 'update',
callback: function () {
$this->domainsUpdate();
},
// mandatoryParameters: ['name'],
// optionalParameters: ['A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>'])))
description: 'Update zone files')))
->addCommandGroup(commandGroup: (new CommandGroup(name: 'dyndns', description: 'handle DynDNS entries'))
->addCommand(command: new Command(
name: 'list',
callback: function () {
$this->dynDnsList();
}))
->addCommand(command: new Command(
name: 'create',
callback: function () {
$this->dynDnsCreate();
},
mandatoryParameters: ['hostname.example.com', 'password'],
optionalParameters: ['A=<IPv4>', 'AAAA=<IPv6>'],
description: 'FQDN within a domain where this server is master'))
->addCommand(command: new Command(
name: 'update',
callback: function () {
$this->dynDnyUpdate();
},
mandatoryParameters: ['hostname.example.com',],
optionalParameters: ['password=<password>', 'A=<IPv4>', 'AAAA=<IPv6>']))
->addCommand(command: new Command(
name: 'delete',
callback: function () {
$this->dynDnsDelete();
},
mandatoryParameters: ['ID'])))
->addCommandGroup(commandGroup: (new CommandGroup(name: 'migrations', description: 'maintain database migrations'))
description: 'Read or set the bindApi version in the database'));
$migrationsGroup = (new CommandGroup(name: 'migrations', description: 'maintain database migrations'))
->addCommand(command: new Command(
name: 'status',
callback: function () {
@ -290,16 +289,32 @@ class CLIController
$this->migrationsMigrate();
},
description: 'Apply a new migration file'
))
->addCommand(command: new Command(
));
$env = $this->configController->getConfig(configKey: 'env');
$makeEnvs = ['dev', 'test'];
if (in_array(needle: $env, haystack: $makeEnvs)) {
$makeMigrationsCommand = new Command(
name: 'make',
callback: function () {
$this->migrationsMake();
},
description: '!Use only on dev environments, not in production! Build a new migration file'
))
description: 'Build a new migration file'
);
$migrationsGroup->addCommand(command: $makeMigrationsCommand);
}
$this->commandGroupContainer = (new CommandGroupContainer())
->addCommandGroup(commandGroup: $apikeyGroup)
->addCommandGroup($cronGroup)
->addCommandGroup($panelsGroup)
->addCommandGroup($domainsGroup)
->addCommandGroup($nameserversGroup)
->addCommandGroup($dyndnsGroup)
->addCommandGroup($checkGroup)
->addCommandGroup($migrationsGroup);
// ->addCommandGroup(commandGroup: (new CommandGroup(name: 'webmail', description: 'manage webmail setup'))
// ->addCommand(command: new Command(