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.
|
||||
*/
|
||||
'Canon' : require('libflitter/canon/CanonicalAccessUnit'),
|
||||
'Config' : require('libflitter/config/ConfigUnit'),
|
||||
'Services' : require('libflitter/services/ServicesUnit'),
|
||||
'Config' : require('./app/compat/ConfigUnit'),
|
||||
'Services' : require('./app/compat/ServicesUnit'),
|
||||
'Utility' : require('libflitter/utility/UtilityUnit'),
|
||||
'Notify' : require('flitter-gotify/src/unit/NotifyUnit'),
|
||||
'Cli' : require('flitter-cli/CliUnit'),
|
||||
'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 {
|
||||
static get services() {
|
||||
return [...super.services, 'utility']
|
||||
return [...super.services, 'utility', 'app']
|
||||
}
|
||||
|
||||
_temp_path_command = 'mktemp -d'
|
||||
@ -39,11 +39,13 @@ class Host extends Injectable {
|
||||
this.config = config
|
||||
this.name = config.name
|
||||
|
||||
const injector = this.app.di()
|
||||
|
||||
if ( config.packages && config.packages.type ) {
|
||||
if ( config.packages.type === 'dnf' ) {
|
||||
this.packages = new DNFManager(this)
|
||||
this.packages = injector.make(DNFManager, this)
|
||||
} else if ( config.packages.type === 'apt' ) {
|
||||
this.packages = new APTManager(this)
|
||||
this.packages = injector.make(APTManager, this)
|
||||
} else {
|
||||
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.type === 'systemd' ) {
|
||||
this.services = new SystemDManager(this)
|
||||
this.services = injector.make(SystemDManager, this)
|
||||
} else {
|
||||
throw new Error(`Invalid or unknown service manager type: ${config.services.type}`)
|
||||
}
|
||||
}
|
||||
|
||||
this.injector = injector
|
||||
}
|
||||
|
||||
async execute(command) {
|
||||
@ -82,16 +86,19 @@ class Host extends Injectable {
|
||||
|
||||
async get_temp_path() {
|
||||
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() {
|
||||
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) {
|
||||
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()
|
||||
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 {
|
||||
static get services() {
|
||||
return [...super.services, 'configs']
|
||||
return [...super.services, 'configs', 'app']
|
||||
}
|
||||
|
||||
_running_hosts = []
|
||||
@ -21,11 +21,11 @@ class hosts extends Service {
|
||||
}
|
||||
|
||||
if ( config.type === 'localhost' ) {
|
||||
const host = new LocalHost(config)
|
||||
const host = this.app.di().make(LocalHost, config)
|
||||
this._running_hosts.push(host)
|
||||
return host
|
||||
} else if ( config.type === 'ssh' ) {
|
||||
const host = new RemoteHost(config)
|
||||
const host = this.app.di().make(RemoteHost, config)
|
||||
this._running_hosts.push(host)
|
||||
return host
|
||||
} else {
|
||||
|
@ -1,48 +1,31 @@
|
||||
// hosts Configuration
|
||||
const hosts = {
|
||||
|
||||
localhost: {
|
||||
type: 'localhost',
|
||||
packages: {
|
||||
type: 'dnf',
|
||||
},
|
||||
services: {
|
||||
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',
|
||||
},
|
||||
},
|
||||
// localhost: {
|
||||
// type: 'localhost',
|
||||
// packages: {
|
||||
// type: 'dnf',
|
||||
// },
|
||||
// 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
|
||||
|
21
package.json
21
package.json
@ -1,17 +1,16 @@
|
||||
{
|
||||
"name": "flitter",
|
||||
"name": "maestro",
|
||||
"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",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.glmdev.tech/flitter/flitter"
|
||||
"url": "https://git.glmdev.tech/garrettmills/maestro"
|
||||
},
|
||||
"keywords": [
|
||||
"flitter",
|
||||
"maestro",
|
||||
"glmdev",
|
||||
"framework",
|
||||
"express"
|
||||
"infrastructure"
|
||||
],
|
||||
"author": "Garrett Mills <garrett@glmdev.tech> (https://glmdev.tech/)",
|
||||
"license": "MIT",
|
||||
@ -19,14 +18,10 @@
|
||||
"axios": "^0.19.2",
|
||||
"cross-zip": "^2.1.6",
|
||||
"flitter-agenda": "^0.5.0",
|
||||
"flitter-auth": "^0.15.1",
|
||||
"flitter-cli": "^0.15.2",
|
||||
"flitter-di": "^0.4.1",
|
||||
"flitter-cli": "^0.16.0",
|
||||
"flitter-di": "^0.5.0",
|
||||
"flitter-flap": "^0.5.2",
|
||||
"flitter-forms": "^0.8.0",
|
||||
"flitter-gotify": "^0.1.0",
|
||||
"flitter-upload": "^0.7.6",
|
||||
"libflitter": "^0.46.8",
|
||||
"libflitter": "^0.53.1",
|
||||
"moment": "^2.24.0",
|
||||
"scp": "^0.0.3",
|
||||
"ssh2": "^0.8.7",
|
||||
|
Loading…
Reference in New Issue
Block a user