parent
57ae564fd7
commit
8c5e048b7c
17 changed files with 150 additions and 66 deletions
@ -0,0 +1,15 @@ |
||||
[package] |
||||
name = "u_panel" |
||||
version = "0.1.0" |
||||
authors = ["plazmoid <kronos44@mail.ru>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
tokio = { version = "*", features = ["macros", "rt-core", "process", "blocking"] } |
||||
log = "^0.4" |
||||
env_logger = "0.7.1" |
||||
uuid = "0.8.1" |
||||
reqwest = { version = "0.10.7", features = ["json"] } |
||||
u_lib = { version = "*", path = "../../lib/u_lib" } |
@ -0,0 +1,27 @@ |
||||
use std::env::args; |
||||
use std::future::Future; |
||||
use u_lib::client::network::ClientHandler; |
||||
|
||||
fn get_cmd_handler(cli_handler: &ClientHandler, method: &str) -> Option<fn()> { |
||||
match method { |
||||
"ls" => Some(cli_handler.list()), |
||||
_ => None |
||||
} |
||||
} |
||||
|
||||
#[tokio::main] |
||||
async fn main() -> Result<(), &'static str> { |
||||
//daemonize();
|
||||
let mut raw_args = args(); |
||||
let method = match raw_args.nth(1) { |
||||
Some(m) => m, |
||||
None => return Err("Method required") |
||||
}; |
||||
let instance = ClientHandler::new(); |
||||
let future = match get_cmd_handler(&instance, &method) { |
||||
Some(c) => c, |
||||
None => return Err("Unknown method") |
||||
}; |
||||
future.await; |
||||
Ok(()) |
||||
} |
@ -1,5 +1,5 @@ |
||||
[package] |
||||
name = "u-run" |
||||
name = "u_run" |
||||
version = "0.1.0" |
||||
authors = ["plazmoid <kronos44@mail.ru>"] |
||||
edition = "2018" |
@ -1,5 +1,5 @@ |
||||
[package] |
||||
name = "u-server" |
||||
name = "u_server" |
||||
version = "0.1.0" |
||||
authors = ["plazmoid <kronos44@mail.ru>"] |
||||
edition = "2018" |
@ -0,0 +1,4 @@ |
||||
pub mod network; |
||||
pub mod client; |
||||
|
||||
pub use client::*; |
@ -1,7 +1,8 @@ |
||||
use u_lib::{ |
||||
use crate::{ |
||||
MASTER_SERVER, |
||||
MASTER_PORT, |
||||
contracts::* |
||||
contracts::*, |
||||
client::* |
||||
}; |
||||
use reqwest::{ |
||||
Client, |
@ -0,0 +1,15 @@ |
||||
use { |
||||
super::*, |
||||
tokio::sync::Mutex, |
||||
std::sync::Arc, |
||||
std::collections::HashMap, |
||||
uuid::Uuid, |
||||
crate::client::* |
||||
}; |
||||
|
||||
|
||||
pub type JobPool = Vec<Box<dyn Job>>; |
||||
pub type JobResult = Result<Vec<u8>, Vec<u8>>; |
||||
|
||||
pub type CliStorage = HashMap<Uuid, UClient>; |
||||
pub type SharedStorage = Arc<Mutex<CliStorage>>; |
@ -1,55 +1,58 @@ |
||||
use std::process::{ |
||||
Command, |
||||
Output |
||||
use std::{ |
||||
process::Command |
||||
}; |
||||
|
||||
pub type JobResult<'res> = Result<&'res [u8], &'res [u8]>; |
||||
//use tokio::process::Command;
|
||||
use super::*; |
||||
|
||||
pub trait Job { |
||||
async fn run(&mut self); |
||||
fn result(&self) -> JobResult; |
||||
fn run(&mut self); |
||||
fn get_result(&self) -> &JobResult; |
||||
} |
||||
|
||||
pub struct ShellJob<'cmd> { |
||||
pub result: JobResult<'cmd>, |
||||
pub cmd: &'cmd str, |
||||
pub args: Vec<&'cmd str> |
||||
pub struct ShellJob { |
||||
pub result: JobResult, |
||||
pub cmd: String, |
||||
pub args: Vec<String> |
||||
} |
||||
|
||||
impl ShellJob { |
||||
pub fn from_raw(raw_cmd: &str) -> Self { |
||||
let cmd_parts = raw_cmd.split(" "); |
||||
pub fn from_raw(raw_cmd: String) -> Self { |
||||
let mut cmd_parts = raw_cmd |
||||
.split(" ") |
||||
.map(String::from) |
||||
.collect::<Vec<String>>(); |
||||
let args: Vec<_> = cmd_parts.drain(1..).collect(); |
||||
Self { |
||||
cmd: cmd_parts[0], |
||||
args: cmd_parts[1..], |
||||
result: Err("Did not run".as_bytes()) |
||||
cmd: cmd_parts.into_iter().nth(1).unwrap(), |
||||
args, |
||||
result: Err(b"Did not run".to_vec()) |
||||
} |
||||
} |
||||
} |
||||
|
||||
impl Job for ShellJob { |
||||
async fn run(&mut self) { |
||||
let result = Command::new(self.cmd) |
||||
impl Job for ShellJob{ |
||||
fn run(&mut self) { |
||||
let result = Command::new(&self.cmd) |
||||
.args(&self.args) |
||||
.output(); |
||||
self.result = match result { |
||||
Ok(output) => { |
||||
if output.status != 0 { |
||||
Err(&output.stderr) |
||||
if output.status.success() { |
||||
Ok(output.stdout.to_vec()) |
||||
} else { |
||||
Ok(&output.stdout) |
||||
Err(output.stderr.to_vec()) |
||||
} |
||||
} |
||||
Err(e) => e.to_string().as_bytes() |
||||
Err(e) => Err(e.to_string().into_bytes()) |
||||
} |
||||
} |
||||
|
||||
fn result(&self) -> JobResult { |
||||
self.result |
||||
fn get_result(&self) -> &JobResult { |
||||
&self.result |
||||
} |
||||
} |
||||
|
||||
/* |
||||
pub struct PyJob { |
||||
|
||||
}*/ |
||||
/* pub struct PyJob {
|
||||
|
||||
} */ |
@ -1,9 +1,12 @@ |
||||
pub mod config; |
||||
pub mod contracts; |
||||
pub mod utils; |
||||
pub mod client; |
||||
|
||||
pub use utils::*; |
||||
pub use config::*; |
||||
pub use { |
||||
utils::*, |
||||
config::*, |
||||
}; |
||||
|
||||
#[macro_use] |
||||
extern crate lazy_static; |
||||
|
Loading…
Reference in new issue