67 lines
2.6 KiB
JavaScript
67 lines
2.6 KiB
JavaScript
const { Service } = require('flitter-di')
|
|
|
|
/*
|
|
* states Service
|
|
* -------------------------------------------------------------
|
|
* This is a service file that will be made available through Flitter's
|
|
* dependency injector to the rest of the application based on its given
|
|
* canonical name.
|
|
*
|
|
* e.g. app.di().service("states")
|
|
*/
|
|
class StatesService extends Service {
|
|
static #state_map = {
|
|
// TODO apache and nginx states - virtual host, reverse proxy
|
|
// TODO package repository states - import keys, install repository
|
|
// TODO service manager states - service enabled, service installed
|
|
|
|
'fs.file': require('../classes/state/fs/FileState'),
|
|
'fs.directory': require('../classes/state/fs/DirectoryState'),
|
|
'fs.unpack': require('../classes/state/fs/UnpackState'),
|
|
'fs.pack': require('../classes/state/fs/PackState'),
|
|
'fs.permission': require('../classes/state/fs/PermissionState'),
|
|
'fs.ownership': require('../classes/state/fs/OwnerState'),
|
|
|
|
'git.clone': require('../classes/state/git/CloneState'),
|
|
'git.checkout': require('../classes/state/git/CheckoutState'),
|
|
'git.tag': require('../classes/state/git/TagState'),
|
|
|
|
'os.cmd': require('../classes/state/os/CommandState'),
|
|
'os.alive': require('../classes/state/os/IsAliveState'),
|
|
|
|
'package.present': require('../classes/state/os/PackageState'),
|
|
'package.absent': require('../classes/state/os/PackageAbsentState'),
|
|
'package.updates': require('../classes/state/os/UpdateState'),
|
|
'package.cache.clear': require('../classes/state/os/PackageCacheClearedState'),
|
|
|
|
'service.running': require('../classes/state/os/ServiceState'),
|
|
'service.stopped': require('../classes/state/os/ServiceStoppedState'),
|
|
'service.restarted': require('../classes/state/os/ServiceRestartState'),
|
|
'service.daemon.reloaded': require('../classes/state/os/ServiceDaemonReloadState'),
|
|
|
|
'web.download': require('../classes/state/fs/DownloadState'),
|
|
}
|
|
|
|
static get services() {
|
|
return [...super.services, 'app', 'configs']
|
|
}
|
|
|
|
map() {
|
|
return this.constructor.#state_map
|
|
}
|
|
|
|
from_config(host, state_config) {
|
|
const type = state_config.type
|
|
state_config = {...state_config}
|
|
delete state_config.type
|
|
|
|
const StepClass = this.constructor.#state_map[type]
|
|
if ( !StepClass ) throw new Error(`Invalid or unknown step type: ${type}`)
|
|
this.app.make(StepClass)
|
|
|
|
return new StepClass(host, state_config)
|
|
}
|
|
}
|
|
|
|
module.exports = exports = StatesService
|