Prepare for first package
This commit is contained in:
parent
8319859828
commit
2c0b126546
@ -17,10 +17,9 @@ const FlitterUnits = {
|
|||||||
* really know what you are doing, you should NEVER change them.
|
* really know what you are doing, you should NEVER change them.
|
||||||
*/
|
*/
|
||||||
'Canon' : require('libflitter/canon/CanonicalAccessUnit'),
|
'Canon' : require('libflitter/canon/CanonicalAccessUnit'),
|
||||||
'Config' : require('libflitter/config/ConfigUnit'),
|
'Config' : require('./app/compat/ConfigUnit'),
|
||||||
'Services' : require('libflitter/services/ServicesUnit'),
|
'Services' : require('./app/compat/ServicesUnit'),
|
||||||
'Utility' : require('libflitter/utility/UtilityUnit'),
|
'Utility' : require('libflitter/utility/UtilityUnit'),
|
||||||
'Notify' : require('flitter-gotify/src/unit/NotifyUnit'),
|
|
||||||
'Cli' : require('flitter-cli/CliUnit'),
|
'Cli' : require('flitter-cli/CliUnit'),
|
||||||
'App' : require('flitter-cli/CliAppUnit'),
|
'App' : require('flitter-cli/CliAppUnit'),
|
||||||
}
|
}
|
||||||
|
43
api.js
Normal file
43
api.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
const units = require('./Units.flitter')
|
||||||
|
delete units.App
|
||||||
|
|
||||||
|
const FlitterApp = require('libflitter/app/FlitterApp')
|
||||||
|
const app = new FlitterApp(units)
|
||||||
|
const services = app.di().container.proxy()
|
||||||
|
let ready = false
|
||||||
|
let ready_ps = []
|
||||||
|
|
||||||
|
app.up().then(() => {
|
||||||
|
ready = true
|
||||||
|
ready_ps.forEach(x => x())
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = exports = {
|
||||||
|
app,
|
||||||
|
services,
|
||||||
|
UniversalPath: require('./app/classes/logical/UniversalPath'),
|
||||||
|
ready: () => ready,
|
||||||
|
ready$: async () => {
|
||||||
|
if ( !ready )
|
||||||
|
return new Promise(res => ready_ps.push(res))
|
||||||
|
},
|
||||||
|
host(name_or_config) {
|
||||||
|
if ( typeof name_or_config === 'object' ) {
|
||||||
|
if ( !name_or_config.name )
|
||||||
|
throw new TypeError('Missing required host property: name')
|
||||||
|
|
||||||
|
if ( services.configs.canonical_items.hosts[name_or_config.name] )
|
||||||
|
throw new TypeError(`A host with the name ${name_or_config.name} is already registered.`)
|
||||||
|
|
||||||
|
services.configs.canonical_items.hosts[name_or_config.name] = name_or_config
|
||||||
|
console.log(services.configs.canonical_items.hosts)
|
||||||
|
return services.hosts.get(name_or_config.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
return services.hosts.get(name_or_config)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.ready$().then(() => {
|
||||||
|
app.di().inject(exports.UniversalPath)
|
||||||
|
})
|
@ -14,7 +14,7 @@ const SystemDManager = require('../logical/services/SystemDManager')
|
|||||||
|
|
||||||
class Host extends Injectable {
|
class Host extends Injectable {
|
||||||
static get services() {
|
static get services() {
|
||||||
return [...super.services, 'utility']
|
return [...super.services, 'utility', 'app']
|
||||||
}
|
}
|
||||||
|
|
||||||
_temp_path_command = 'mktemp -d'
|
_temp_path_command = 'mktemp -d'
|
||||||
@ -39,11 +39,13 @@ class Host extends Injectable {
|
|||||||
this.config = config
|
this.config = config
|
||||||
this.name = config.name
|
this.name = config.name
|
||||||
|
|
||||||
|
const injector = this.app.di()
|
||||||
|
|
||||||
if ( config.packages && config.packages.type ) {
|
if ( config.packages && config.packages.type ) {
|
||||||
if ( config.packages.type === 'dnf' ) {
|
if ( config.packages.type === 'dnf' ) {
|
||||||
this.packages = new DNFManager(this)
|
this.packages = injector.make(DNFManager, this)
|
||||||
} else if ( config.packages.type === 'apt' ) {
|
} else if ( config.packages.type === 'apt' ) {
|
||||||
this.packages = new APTManager(this)
|
this.packages = injector.make(APTManager, this)
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Invalid or unknown package manager type: ${config.packages.type}`)
|
throw new Error(`Invalid or unknown package manager type: ${config.packages.type}`)
|
||||||
}
|
}
|
||||||
@ -51,11 +53,13 @@ class Host extends Injectable {
|
|||||||
|
|
||||||
if ( config.services && config.services.type ) {
|
if ( config.services && config.services.type ) {
|
||||||
if ( config.services.type === 'systemd' ) {
|
if ( config.services.type === 'systemd' ) {
|
||||||
this.services = new SystemDManager(this)
|
this.services = injector.make(SystemDManager, this)
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Invalid or unknown service manager type: ${config.services.type}`)
|
throw new Error(`Invalid or unknown service manager type: ${config.services.type}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.injector = injector
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(command) {
|
async execute(command) {
|
||||||
@ -82,16 +86,19 @@ class Host extends Injectable {
|
|||||||
|
|
||||||
async get_temp_path() {
|
async get_temp_path() {
|
||||||
const path_string = await this.run_line_result(this._temp_path_command)
|
const path_string = await this.run_line_result(this._temp_path_command)
|
||||||
return new UniversalPath(this, path_string, UniversalPath.PATH_TYPE_DIRECTORY)
|
return this.injector.make(UniversalPath, this, path_string, UniversalPath.PATH_TYPE_DIRECTORY)
|
||||||
|
// return new UniversalPath(this, path_string, UniversalPath.PATH_TYPE_DIRECTORY)
|
||||||
}
|
}
|
||||||
|
|
||||||
async get_temp_file() {
|
async get_temp_file() {
|
||||||
const file_string = await this.run_line_result(this._temp_file_command)
|
const file_string = await this.run_line_result(this._temp_file_command)
|
||||||
return new UniversalPath(this, file_string, UniversalPath.PATH_TYPE_FILE)
|
return this.injector.make(UniversalPath, this, file_string, UniversalPath.PATH_TYPE_FILE)
|
||||||
|
// return new UniversalPath(this, file_string, UniversalPath.PATH_TYPE_FILE)
|
||||||
}
|
}
|
||||||
|
|
||||||
async get_path(local_path) {
|
async get_path(local_path) {
|
||||||
const host_path = new UniversalPath(this, local_path)
|
const host_path = this.injector.make(UniversalPath, this, local_path)
|
||||||
|
// const host_path = new UniversalPath(this, local_path)
|
||||||
await host_path.classify()
|
await host_path.classify()
|
||||||
return host_path
|
return host_path
|
||||||
}
|
}
|
||||||
|
19
app/compat/ConfigUnit.js
Normal file
19
app/compat/ConfigUnit.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
const ConfigUnit = require('libflitter/config/ConfigUnit')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
|
class CompatConfigUnit extends ConfigUnit {
|
||||||
|
/**
|
||||||
|
* Get the name of the service provided by this unit: 'services'
|
||||||
|
* @returns {string} - 'services'
|
||||||
|
*/
|
||||||
|
static get name() {
|
||||||
|
return 'configs'
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
const base_dir = path.resolve(__dirname, '..', '..', 'config')
|
||||||
|
super(base_dir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = exports = CompatConfigUnit
|
19
app/compat/ServicesUnit.js
Normal file
19
app/compat/ServicesUnit.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
const ServicesUnit = require('libflitter/services/ServicesUnit')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
|
class CompatServicesUnit extends ServicesUnit {
|
||||||
|
/**
|
||||||
|
* Get the name of the service provided by this unit: 'services'
|
||||||
|
* @returns {string} - 'services'
|
||||||
|
*/
|
||||||
|
static get name() {
|
||||||
|
return 'services'
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
const base_dir = path.resolve(__dirname, '..', 'services')
|
||||||
|
super(base_dir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = exports = CompatServicesUnit
|
@ -4,7 +4,7 @@ const RemoteHost = require('../classes/metal/RemoteHost')
|
|||||||
|
|
||||||
class hosts extends Service {
|
class hosts extends Service {
|
||||||
static get services() {
|
static get services() {
|
||||||
return [...super.services, 'configs']
|
return [...super.services, 'configs', 'app']
|
||||||
}
|
}
|
||||||
|
|
||||||
_running_hosts = []
|
_running_hosts = []
|
||||||
@ -21,11 +21,11 @@ class hosts extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( config.type === 'localhost' ) {
|
if ( config.type === 'localhost' ) {
|
||||||
const host = new LocalHost(config)
|
const host = this.app.di().make(LocalHost, config)
|
||||||
this._running_hosts.push(host)
|
this._running_hosts.push(host)
|
||||||
return host
|
return host
|
||||||
} else if ( config.type === 'ssh' ) {
|
} else if ( config.type === 'ssh' ) {
|
||||||
const host = new RemoteHost(config)
|
const host = this.app.di().make(RemoteHost, config)
|
||||||
this._running_hosts.push(host)
|
this._running_hosts.push(host)
|
||||||
return host
|
return host
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,48 +1,31 @@
|
|||||||
// hosts Configuration
|
// hosts Configuration
|
||||||
const hosts = {
|
const hosts = {
|
||||||
|
|
||||||
localhost: {
|
// localhost: {
|
||||||
type: 'localhost',
|
// type: 'localhost',
|
||||||
packages: {
|
// packages: {
|
||||||
type: 'dnf',
|
// type: 'dnf',
|
||||||
},
|
// },
|
||||||
services: {
|
// services: {
|
||||||
type: 'systemd',
|
// type: 'systemd',
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
|
|
||||||
core: {
|
|
||||||
type: 'ssh',
|
|
||||||
ssh_params: {
|
|
||||||
port: 60022,
|
|
||||||
username: 'root',
|
|
||||||
host: 'core.infrastructure',
|
|
||||||
key_file: '/home/garrettmills/.ssh/id_rsa',
|
|
||||||
},
|
|
||||||
packages: {
|
|
||||||
type: 'apt',
|
|
||||||
},
|
|
||||||
services: {
|
|
||||||
type: 'systemd',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
edge: {
|
|
||||||
type: 'ssh',
|
|
||||||
ssh_params: {
|
|
||||||
port: 60022,
|
|
||||||
username: 'root',
|
|
||||||
host: 'edge.infrastructure',
|
|
||||||
key_file: '/home/garrettmills/.ssh/id_rsa',
|
|
||||||
},
|
|
||||||
packages: {
|
|
||||||
type: 'apt',
|
|
||||||
},
|
|
||||||
services: {
|
|
||||||
type: 'systemd',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
|
// core: {
|
||||||
|
// type: 'ssh',
|
||||||
|
// ssh_params: {
|
||||||
|
// port: 60022,
|
||||||
|
// username: 'root',
|
||||||
|
// host: 'core',
|
||||||
|
// key_file: '/home/user/.ssh/id_rsa',
|
||||||
|
// },
|
||||||
|
// packages: {
|
||||||
|
// type: 'apt', // apt | dnf
|
||||||
|
// },
|
||||||
|
// services: {
|
||||||
|
// type: 'systemd', // systemd
|
||||||
|
// },
|
||||||
|
// },
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = exports = hosts
|
module.exports = exports = hosts
|
||||||
|
21
package.json
21
package.json
@ -1,17 +1,16 @@
|
|||||||
{
|
{
|
||||||
"name": "flitter",
|
"name": "maestro",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "Flitter is a simple MVC framework wrapper for Express.js.",
|
"description": "Maestro is an object-oriented library for interacting with remote infrastructure.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://git.glmdev.tech/flitter/flitter"
|
"url": "https://git.glmdev.tech/garrettmills/maestro"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"flitter",
|
"maestro",
|
||||||
"glmdev",
|
"glmdev",
|
||||||
"framework",
|
"infrastructure"
|
||||||
"express"
|
|
||||||
],
|
],
|
||||||
"author": "Garrett Mills <garrett@glmdev.tech> (https://glmdev.tech/)",
|
"author": "Garrett Mills <garrett@glmdev.tech> (https://glmdev.tech/)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@ -19,14 +18,10 @@
|
|||||||
"axios": "^0.19.2",
|
"axios": "^0.19.2",
|
||||||
"cross-zip": "^2.1.6",
|
"cross-zip": "^2.1.6",
|
||||||
"flitter-agenda": "^0.5.0",
|
"flitter-agenda": "^0.5.0",
|
||||||
"flitter-auth": "^0.15.1",
|
"flitter-cli": "^0.16.0",
|
||||||
"flitter-cli": "^0.15.2",
|
"flitter-di": "^0.5.0",
|
||||||
"flitter-di": "^0.4.1",
|
|
||||||
"flitter-flap": "^0.5.2",
|
"flitter-flap": "^0.5.2",
|
||||||
"flitter-forms": "^0.8.0",
|
"libflitter": "^0.53.1",
|
||||||
"flitter-gotify": "^0.1.0",
|
|
||||||
"flitter-upload": "^0.7.6",
|
|
||||||
"libflitter": "^0.46.8",
|
|
||||||
"moment": "^2.24.0",
|
"moment": "^2.24.0",
|
||||||
"scp": "^0.0.3",
|
"scp": "^0.0.3",
|
||||||
"ssh2": "^0.8.7",
|
"ssh2": "^0.8.7",
|
||||||
|
Loading…
Reference in New Issue
Block a user