maestro/app/services/states.service.js

67 lines
2.6 KiB
JavaScript
Raw Normal View History

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
2020-03-07 03:14:15 +00:00
// TODO service manager states - service enabled, service installed
'fs.file': require('../classes/state/fs/FileState'),
'fs.directory': require('../classes/state/fs/DirectoryState'),
2020-03-03 22:10:10 +00:00
'fs.unpack': require('../classes/state/fs/UnpackState'),
'fs.pack': require('../classes/state/fs/PackState'),
2020-03-03 22:47:51 +00:00
'fs.permission': require('../classes/state/fs/PermissionState'),
'fs.ownership': require('../classes/state/fs/OwnerState'),
2020-03-05 17:48:38 +00:00
'git.clone': require('../classes/state/git/CloneState'),
'git.checkout': require('../classes/state/git/CheckoutState'),
'git.tag': require('../classes/state/git/TagState'),
2020-03-05 17:48:38 +00:00
2020-03-05 16:30:24 +00:00
'os.cmd': require('../classes/state/os/CommandState'),
'os.alive': require('../classes/state/os/IsAliveState'),
2020-03-05 16:30:24 +00:00
'package.present': require('../classes/state/os/PackageState'),
2020-03-06 15:49:08 +00:00
'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'),
2020-03-07 03:14:15 +00:00
'service.stopped': require('../classes/state/os/ServiceStoppedState'),
'service.restarted': require('../classes/state/os/ServiceRestartState'),
'service.daemon.reloaded': require('../classes/state/os/ServiceDaemonReloadState'),
2020-03-03 22:10:10 +00:00
'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