Add support for running routines via command line

This commit is contained in:
garrettmills
2020-08-13 20:28:23 -05:00
parent afb35ebad8
commit f5b84b530c
33 changed files with 396 additions and 5 deletions

View File

@@ -27,6 +27,10 @@ class State extends Injectable {
check_message() {
throw new ImplementationError()
}
display() {
return this.constructor.name
}
}
module.exports = exports = State

View File

@@ -34,6 +34,10 @@ class DirectoryState extends State {
check_message() {
return this.failure_message()
}
display() {
return `Ensure that the directory ${this._config.path} exists...`
}
}
module.exports = exports = DirectoryState

View File

@@ -54,6 +54,10 @@ class DownloadState extends State {
check_message() {
return this.failure_message()
}
display() {
return `Ensure that the file ${this._config.path} is downloaded from ${this._config.source}...`
}
}
module.exports = exports = DownloadState

View File

@@ -39,6 +39,10 @@ class FileState extends State {
check_message() {
return this.failure_message()
}
display() {
return `Ensure that the file ${this._config.path} exists...`
}
}
module.exports = exports = FileState

View File

@@ -46,6 +46,10 @@ class OwnerState extends State {
check_message() {
return this.failure_message()
}
display() {
return `Set filesystem owner of resource ${this._config.path}...`
}
}
module.exports = exports = OwnerState

View File

@@ -63,6 +63,10 @@ class PackState extends State {
check_message() {
return this.failure_message()
}
display() {
return `Archive the contents of ${this._config.path} to ${this._config.destination}...`
}
}
module.exports = exports = PackState

View File

@@ -42,6 +42,10 @@ class PermissionState extends State {
check_message() {
return this.failure_message()
}
display() {
return `Set filesystem permissions of resource ${this._config.path}...`
}
}
module.exports = exports = PermissionState

View File

@@ -66,6 +66,10 @@ class UnpackState extends State {
check_message() {
return this.failure_message()
}
display() {
return `Un-archive the contents of ${this._config.path} to ${this._config.destination}...`
}
}
module.exports = exports = UnpackState

View File

@@ -40,6 +40,10 @@ class CheckoutState extends AbstractGitState {
check_message() {
return this.failure_message()
}
display() {
return `Check out ref ${this._config.target} in repo ${this._config.path}...`
}
}
module.exports = exports = CheckoutState

View File

@@ -30,6 +30,10 @@ class CloneState extends AbstractGitState {
check_message() {
return this.failure_message()
}
display() {
return `Clone repo at ${this._config.source} to ${this._config.path}...`
}
}
module.exports = exports = CloneState

View File

@@ -0,0 +1,36 @@
const AbstractGitState = require('./AbstractGitState')
class PullState extends AbstractGitState {
static get services() {
return [...super.services, 'output']
}
async apply() {
if ( !(await this.check()) ) {
const repo = await this._repo()
await repo.pull(this._config.target)
}
}
async check() {
return true // TODO support a better check here
}
async reverse() {
this.output.warn('Pull state does not currently support automatic reversal.')
}
failure_message() {
return `The Git repo at "${this._config.path}" on host "${this._host.name}" will be pulled.`
}
check_message() {
return this.failure_message()
}
display() {
return `Pull refs in repo ${this._config.path}...`
}
}
module.exports = exports = PullState

View File

@@ -33,6 +33,10 @@ class TagState extends AbstractGitState {
check_message() {
return this.failure_message()
}
display() {
return `Create tag ${this._config.tag} in repo ${this._config.path}...`
}
}
module.exports = exports = TagState

View File

@@ -1,17 +1,20 @@
const State = require('../State')
class CommandState extends State {
#ran_once = false
static get services() {
return [...super.services, 'output']
}
async apply() {
const cmd = `${this._config.cmd}`
await this._host.run(cmd)
const result = await this._host.run(cmd)
this.#ran_once = true
}
async check() {
return false
return this.#ran_once
}
async reverse() {
@@ -30,6 +33,10 @@ class CommandState extends State {
check_message() {
return `The command check was not successful.`
}
display() {
return `Run the command: ${this._config.cmd}`
}
}
module.exports = exports = CommandState

View File

@@ -20,6 +20,10 @@ class IsAliveState extends State {
check_message() {
return this.failure_message()
}
display() {
return `Ensure that the host is alive...`
}
}
module.exports = exports = IsAliveState

View File

@@ -27,6 +27,10 @@ class PackageAbsentState extends State {
check_message() {
return this.failure_message()
}
display() {
return `Ensure that the package ${this._config.package} is not installed...`
}
}
module.exports = exports = PackageAbsentState

View File

@@ -31,6 +31,10 @@ class PackageCacheClearedState extends State {
check_message() {
return `The package cache on host "${this._host.name}" has not been cleared.`
}
display() {
return `Ensure that the package cache is cleared...`
}
}
module.exports = exports = PackageCacheClearedState

View File

@@ -27,6 +27,10 @@ class PackageState extends State {
check_message() {
return this.failure_message()
}
display() {
return `Ensure that the package ${this._config.package} is installed...`
}
}
module.exports = exports = PackageState

View File

@@ -31,6 +31,10 @@ class ServiceDaemonReloadState extends State {
check_message() {
return `The service daemon on host "${this._host.name}" has not been reloaded.`
}
display() {
return `Reload the service daemon...`
}
}
module.exports = exports = ServiceDaemonReloadState

View File

@@ -32,6 +32,10 @@ class ServiceRestartState extends State {
check_message() {
return `The service "${this._config.service}" on host "${this._host.name}" has not been restarted.`
}
display() {
return `Restart the ${this._config.service} service...`
}
}
module.exports = exports = ServiceRestartState

View File

@@ -33,6 +33,10 @@ class ServiceState extends State {
check_message() {
return this.failure_message()
}
display() {
return `Ensure that the ${this._config.service} service is running...`
}
}
module.exports = exports = ServiceState

View File

@@ -32,6 +32,10 @@ class ServiceStoppedState extends State {
check_message() {
return `The service "${this._config.service}" on host "${this._host.name}" has not been stopped.`
}
display() {
return `Ensure that the ${this._config.service} service is not running...`
}
}
module.exports = exports = ServiceStoppedState

View File

@@ -32,6 +32,10 @@ class UpdateState extends State {
check_message() {
return `There are package updates pending on the host "${this._host.name}."`
}
display() {
return `Ensure that all packages are up to date...`
}
}
module.exports = exports = UpdateState