maestro/app/services/states.service.js
2020-02-27 00:31:07 -06:00

51 lines
1.9 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 file/directory permissions state - chmod & chown
// TODO file download state
// TODO file unpack state - zips, tarballs
// TODO package repository states - import keys, install repository
// TODO service manager states - service enabled, service installed
// TODO git states - clone repo, ref checked out
'fs.file': require('../classes/state/fs/FileState'),
'fs.directory': require('../classes/state/fs/DirectoryState'),
'package.present': require('../classes/state/os/PackageState'),
'package.updates': require('../classes/state/os/UpdateState'),
'package.cache.clear': require('../classes/state/os/PackageCacheClearedState'),
'service.running': require('../classes/state/os/ServiceState'),
'service.restarted': require('../classes/state/os/ServiceRestartState'),
'service.daemon.reloaded': require('../classes/state/os/ServiceDaemonReloadState'),
}
static get services() {
return [...super.services, 'app', 'configs']
}
from_config(host, state_config) {
const type = state_config.type
delete state_config.type
const StepClass = this.constructor.#state_map[type]
this.app.di().make(StepClass)
if ( !StepClass ) throw new Error(`Invalid or unknown step type: ${type}`)
return new StepClass(host, state_config)
}
}
module.exports = exports = StatesService