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,243 +63,258 @@ 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'))
->addCommand(command: new Command(
name: 'list',
callback: function () {
$this->apikeysList();
}
)
)
->addCommand(command: new Command(
name: 'create',
callback: function () {
$this->apikeysCreate();
},
mandatoryParameters: ['name'])
)
->addCommand(command: new Command(
name: 'update',
callback: function () {
$this->apikeysUpdate();
},
mandatoryParameters: ['ID',],
optionalParameters: ['name=<name>']))
->addCommand(command: new Command(
name: 'delete',
callback: function () {
$this->apikeysDelete();
},
mandatoryParameters: ['ID'])))
->addCommandGroup(commandGroup: (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'))
->addCommand(command: new Command(
name: 'cache',
callback: function () {
$this->checkCache();
},
description: 'Clear the opcache. Note: It doesn\'t call composer clear-cache.'))
->addCommand(command: new Command(
name: 'permissions',
callback: function () {
$this->checkPermissions();
},
description: 'check file permissions'))
->addCommand(command: new Command(
name: 'panel',
callback: function () {
$this->checkPanel();
},
description: 'Validate setting for this panel'))
->addCommand(command: new Command(
name: 'panels',
callback: function () {
$this->checkPanels();
},
optionalParameters: ['ID', 'fix=xes']))
->addCommand(command: new Command(
name: 'nameserver',
callback: function () {
$this->checkNameserver();
},
description: 'Validate setting for this panel'))
->addCommand(command: new Command(
name: 'nameservers',
callback: function () {
$this->checkNameservers();
},
description: 'Check version on nameservers'))
->addCommand(command: new Command(
name: 'domains',
callback: function () {
$this->checkDomains();
}))
->addCommand(command: new Command(
name: 'mail',
callback: function () {
$this->checkMail();
}))
->addCommand(command: new Command(
name: 'showincludes',
callback: function () {
$this->checkShowIncludes();
},
description: 'Shows needed setting on panels'))
->addCommand(command: new Command(
name: 'generatekey',
callback: function () {
$this->checkGenerateKey();
},
description: 'Generates a a new key for encryption'))
->addCommand(command: new Command(
name: 'setup',
callback: function () {
$this->checkSetup();
},
mandatoryParameters: ['username'],
description: 'Adapt filesystem permissions (requires elaborated permissions)'))
->addCommand(command: new Command(
name: 'version',
callback: function () {
$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();
},
$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',
callback: function () {
$this->apikeysCreate();
},
mandatoryParameters: ['name'])
)
->addCommand(command: new Command(
name: 'update',
callback: function () {
$this->apikeysUpdate();
},
mandatoryParameters: ['ID',],
optionalParameters: ['name=<name>']))
->addCommand(command: new Command(
name: 'delete',
callback: function () {
$this->apikeysDelete();
},
mandatoryParameters: ['ID']
));
$cronGroup = (new CommandGroup(name: 'cron', description: 'Run zone file maintenance'))
->addCommand(command: new Command(
name: 'run',
callback: function () {
$this->cronRun();
}));
$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')))
->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'))
->addCommand(command: new Command(
name: 'status',
callback: function () {
$this->migrationsStatus();
},
description: 'List information about migrations'
))
->addCommand(command: new Command(
name: 'migrate',
callback: function () {
$this->migrationsMigrate();
},
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'
))
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 () {
$this->checkCache();
},
description: 'Clear the opcache. Note: It doesn\'t call composer clear-cache.'))
->addCommand(command: new Command(
name: 'permissions',
callback: function () {
$this->checkPermissions();
},
description: 'check file permissions'))
->addCommand(command: new Command(
name: 'panel',
callback: function () {
$this->checkPanel();
},
description: 'Validate setting for this panel'))
->addCommand(command: new Command(
name: 'panels',
callback: function () {
$this->checkPanels();
},
optionalParameters: ['ID', 'fix=xes']))
->addCommand(command: new Command(
name: 'nameserver',
callback: function () {
$this->checkNameserver();
},
description: 'Validate setting for this panel'))
->addCommand(command: new Command(
name: 'nameservers',
callback: function () {
$this->checkNameservers();
},
description: 'Check version on nameservers'))
->addCommand(command: new Command(
name: 'domains',
callback: function () {
$this->checkDomains();
}))
->addCommand(command: new Command(
name: 'mail',
callback: function () {
$this->checkMail();
}))
->addCommand(command: new Command(
name: 'showincludes',
callback: function () {
$this->checkShowIncludes();
},
description: 'Shows needed setting on panels'))
->addCommand(command: new Command(
name: 'generatekey',
callback: function () {
$this->checkGenerateKey();
},
description: 'Generates a a new key for encryption'))
->addCommand(command: new Command(
name: 'setup',
callback: function () {
$this->checkSetup();
},
mandatoryParameters: ['username'],
description: 'Adapt filesystem permissions (requires elaborated permissions)'))
->addCommand(command: new Command(
name: 'version',
callback: function () {
$this->checkVersion();
},
optionalParameters: ['update'],
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 () {
$this->migrationsStatus();
},
description: 'List information about migrations'
))
->addCommand(command: new Command(
name: 'migrate',
callback: function () {
$this->migrationsMigrate();
},
description: 'Apply a new migration file'
));
$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: '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(