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", "name": "tracer/bindapi",
"description": "manage Bind9 DNS server via REST API", "description": "manage Bind9 client zones for KeyHelp",
"version": "1.0.9", "version": "1.0.9",
"build_number": "375", "build_number": "376",
"authors": [ "authors": [
{ {
"name": "Micha Espey", "name": "Micha Espey",

View File

@ -63,243 +63,258 @@ class CLIController
{ {
$this->baseDir = dirname(path: __DIR__, levels: 2) . '/'; $this->baseDir = dirname(path: __DIR__, levels: 2) . '/';
$this->commandGroupContainer = (new CommandGroupContainer()) $apikeyGroup = (new CommandGroup(name: 'apikeys', description: 'API keys to access this bindAPI'))
->addCommandGroup(commandGroup: (new CommandGroup(name: 'apikeys', description: 'API keys to access this bindAPI')) ->addCommand(command: new Command(
->addCommand(command: new Command( name: 'list',
name: 'list', callback: function () {
callback: function () { $this->apikeysList();
$this->apikeysList(); })
} )
) ->addCommand(command: new Command(
) name: 'create',
->addCommand(command: new Command( callback: function () {
name: 'create', $this->apikeysCreate();
callback: function () { },
$this->apikeysCreate(); mandatoryParameters: ['name'])
}, )
mandatoryParameters: ['name']) ->addCommand(command: new Command(
) name: 'update',
->addCommand(command: new Command( callback: function () {
name: 'update', $this->apikeysUpdate();
callback: function () { },
$this->apikeysUpdate(); mandatoryParameters: ['ID',],
}, optionalParameters: ['name=<name>']))
mandatoryParameters: ['ID',], ->addCommand(command: new Command(
optionalParameters: ['name=<name>'])) name: 'delete',
->addCommand(command: new Command( callback: function () {
name: 'delete', $this->apikeysDelete();
callback: function () { },
$this->apikeysDelete(); mandatoryParameters: ['ID']
}, ));
mandatoryParameters: ['ID']))) $cronGroup = (new CommandGroup(name: 'cron', description: 'Run zone file maintenance'))
->addCommandGroup(commandGroup: (new CommandGroup(name: 'cron', description: 'Run zone file maintenance')) ->addCommand(command: new Command(
->addCommand(command: new Command( name: 'run',
name: 'run', callback: function () {
callback: function () { $this->cronRun();
$this->cronRun(); }));
}))) $panelsGroup = (new CommandGroup(name: 'panels', description: 'all KeyHelp systems configured'))
->addCommandGroup(commandGroup: (new CommandGroup(name: 'check', description: 'health checks the system can perform')) ->addCommand(command: new Command(
->addCommand(command: new Command( name: 'list',
name: 'cache', callback: function () {
callback: function () { $this->panelsList();
$this->checkCache(); }))
}, ->addCommand(command: new Command(
description: 'Clear the opcache. Note: It doesn\'t call composer clear-cache.')) name: 'create',
->addCommand(command: new Command( callback: function () {
name: 'permissions', $this->panelsCreate();
callback: function () { },
$this->checkPermissions(); mandatoryParameters: ['name'],
}, optionalParameters: ['A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>', 'self=<yes|no>']))
description: 'check file permissions')) ->addCommand(command: new Command(
->addCommand(command: new Command( name: 'update',
name: 'panel', callback: function () {
callback: function () { $this->panelsUpdate();
$this->checkPanel(); },
}, mandatoryParameters: ['ID'],
description: 'Validate setting for this panel')) optionalParameters: ['name=<name>', 'A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>', 'self=<yes|no>']))
->addCommand(command: new Command( ->addCommand(command: new Command(
name: 'panels', name: 'delete',
callback: function () { callback: function () {
$this->checkPanels(); $this->panelsDelete();
}, },
optionalParameters: ['ID', 'fix=xes'])) mandatoryParameters: ['ID']))
->addCommand(command: new Command( ->addCommand(command: new Command(
name: 'nameserver', name: 'apiping',
callback: function () { callback: function () {
$this->checkNameserver(); $this->apiPing(type: 'panel');
}, },
description: 'Validate setting for this panel')) optionalParameters: ['ID']));
->addCommand(command: new Command( $domainsGroup = (new CommandGroup(name: 'domains', description: 'configured domains'))
name: 'nameservers', ->addCommand(command: new Command(
callback: function () { name: 'list',
$this->checkNameservers(); callback: function () {
}, $this->domainsList();
description: 'Check version on nameservers')) }))
->addCommand(command: new Command( ->addCommand(command: new Command(
name: 'domains', name: 'update',
callback: function () { callback: function () {
$this->checkDomains(); $this->domainsUpdate();
})) },
->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();
},
// mandatoryParameters: ['name'], // mandatoryParameters: ['name'],
// optionalParameters: ['A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>']))) // optionalParameters: ['A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>'])))
description: 'Update zone files'))) description: 'Update zone files'));
->addCommandGroup(commandGroup: (new CommandGroup(name: 'dyndns', description: 'handle DynDNS entries')) $nameserversGroup = (new CommandGroup(name: 'nameservers', description: 'available nameservers'))
->addCommand(command: new Command( ->addCommand(command: new Command(
name: 'list', name: 'list',
callback: function () { callback: function () {
$this->dynDnsList(); $this->nameserversList();
})) }))
->addCommand(command: new Command( ->addCommand(command: new Command(
name: 'create', name: 'create',
callback: function () { callback: function () {
$this->dynDnsCreate(); $this->nameserversCreate();
}, },
mandatoryParameters: ['hostname.example.com', 'password'], mandatoryParameters: ['name'],
optionalParameters: ['A=<IPv4>', 'AAAA=<IPv6>'], optionalParameters: ['A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>']))
description: 'FQDN within a domain where this server is master')) ->addCommand(command: new Command(
->addCommand(command: new Command( name: 'update',
name: 'update', callback: function () {
callback: function () { $this->nameserversUpdate();
$this->dynDnyUpdate(); },
}, mandatoryParameters: ['ID'],
mandatoryParameters: ['hostname.example.com',], optionalParameters: ['name=<name>', 'A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>']))
optionalParameters: ['password=<password>', 'A=<IPv4>', 'AAAA=<IPv6>'])) ->addCommand(command: new Command(
->addCommand(command: new Command( name: 'delete',
name: 'delete', callback: function () {
callback: function () { $this->nameserversDelete();
$this->dynDnsDelete(); },
}, mandatoryParameters: ['ID']))
mandatoryParameters: ['ID']))) ->addCommand(command: new Command(
->addCommandGroup(commandGroup: (new CommandGroup(name: 'migrations', description: 'maintain database migrations')) name: 'apiping',
->addCommand(command: new Command( callback: function () {
name: 'status', $this->apiPing(type: 'nameserver');
callback: function () { },
$this->migrationsStatus(); optionalParameters: ['ID']));
}, $dyndnsGroup = (new CommandGroup(name: 'dyndns', description: 'handle DynDNS entries'))
description: 'List information about migrations' ->addCommand(command: new Command(
)) name: 'list',
->addCommand(command: new Command( callback: function () {
name: 'migrate', $this->dynDnsList();
callback: function () { }))
$this->migrationsMigrate(); ->addCommand(command: new Command(
}, name: 'create',
description: 'Apply a new migration file' callback: function () {
)) $this->dynDnsCreate();
->addCommand(command: new Command( },
name: 'make', mandatoryParameters: ['hostname.example.com', 'password'],
callback: function () { optionalParameters: ['A=<IPv4>', 'AAAA=<IPv6>'],
$this->migrationsMake(); description: 'FQDN within a domain where this server is master'))
}, ->addCommand(command: new Command(
description: '!Use only on dev environments, not in production! Build a new migration file' 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')) // ->addCommandGroup(commandGroup: (new CommandGroup(name: 'webmail', description: 'manage webmail setup'))
// ->addCommand(command: new Command( // ->addCommand(command: new Command(