|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
const { Injectable } = require('flitter-di')
|
|
|
|
|
const ImplementationError = require('libflitter/errors/ImplementationError')
|
|
|
|
|
const PermissionDeniedError = require('../logical/error/PermissionDeniedError')
|
|
|
|
|
const uuid = require('uuid/v4')
|
|
|
|
|
const UniversalPath = require('../logical/UniversalPath')
|
|
|
|
|
const SystemMetrics = require('../logical/SystemMetrics')
|
|
|
|
@ -178,7 +179,8 @@ class Host extends Injectable {
|
|
|
|
|
async run_line_result(command) {
|
|
|
|
|
const result = await this.execute(command)
|
|
|
|
|
if ( result.exit_code !== 0 || result.clean_out.length < 1 ) {
|
|
|
|
|
throw new Error('Unable to get line output from command: '+command)
|
|
|
|
|
const E = this._get_result_error_class(result)
|
|
|
|
|
throw new E('Unable to get line output from command: '+command)
|
|
|
|
|
}
|
|
|
|
|
return this.utility.infer(result.clean_out[0].trim())
|
|
|
|
|
}
|
|
|
|
@ -186,7 +188,8 @@ class Host extends Injectable {
|
|
|
|
|
async run(command) {
|
|
|
|
|
const result = await this.execute(command)
|
|
|
|
|
if ( result.exit_code !== 0 ) {
|
|
|
|
|
throw new Error('Unable to run command: '+command)
|
|
|
|
|
const E = this._get_result_error_class(result)
|
|
|
|
|
throw new E('Unable to run command: '+command)
|
|
|
|
|
}
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
@ -200,6 +203,22 @@ class Host extends Injectable {
|
|
|
|
|
async reboot() {
|
|
|
|
|
await this.run_line_result(this._reboot_command)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_get_result_error_class(result) {
|
|
|
|
|
const both = `${result.clean_out}\n${result.clean_err}`.toLowerCase()
|
|
|
|
|
const access_denied_phrases = [
|
|
|
|
|
'not permitted',
|
|
|
|
|
'access denied',
|
|
|
|
|
'insufficient permission',
|
|
|
|
|
'permission denied'
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
for ( const phrase of access_denied_phrases ) {
|
|
|
|
|
if ( both.includes(phrase) ) return PermissionDeniedError
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Error
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = exports = Host
|
|
|
|
|