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, stopped // TODO git states - clone repo, ref checked out // TODO package states - uninstalled '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'), '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'), 'web.download': require('../classes/state/fs/DownloadState'), } 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