new features during cli rework
parent
848b321228
commit
afeece915c
|
|
@ -0,0 +1 @@
|
|||
NOXIS_SOCKET_PATH = "/home/vladislavd/diplom_code/noxis-rs/noxis.sock"
|
||||
|
|
@ -6,6 +6,7 @@ edition = "2021"
|
|||
[dependencies]
|
||||
anyhow = "1.0.94"
|
||||
clap = { version = "4.5.22", features = ["derive"] }
|
||||
dotenv = "0.15.0"
|
||||
serde = { version = "1.0.215", features = ["derive"] }
|
||||
serde_json = "1.0.133"
|
||||
thiserror = "2.0.11"
|
||||
|
|
|
|||
|
|
@ -79,7 +79,23 @@ pub enum ConfigAction {
|
|||
about = "To reset all config settings",
|
||||
)]
|
||||
Reset,
|
||||
#[command(
|
||||
about = "To get current Noxis configuration",
|
||||
name = "ls"
|
||||
)]
|
||||
Show(EnvConfig),
|
||||
}
|
||||
#[derive(Debug, Parser, serde::Serialize, serde::Deserialize)]
|
||||
pub struct EnvConfig {
|
||||
// flag
|
||||
#[arg(
|
||||
long = "env",
|
||||
action,
|
||||
help = "to read environment vars configuration",
|
||||
)]
|
||||
pub is_env : bool,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Parser, serde::Serialize, serde::Deserialize)]
|
||||
pub struct LocalConfig {
|
||||
|
|
@ -148,4 +164,28 @@ pub enum ProcessAction {
|
|||
about = "To get info about current process's services-dependencies",
|
||||
)]
|
||||
Services,
|
||||
}
|
||||
|
||||
pub mod metrics_models {
|
||||
pub enum MetricsMode {
|
||||
Full,
|
||||
// system
|
||||
Cpu,
|
||||
Memory,
|
||||
Ram,
|
||||
Rom,
|
||||
Network,
|
||||
// processes
|
||||
Processes
|
||||
// Config
|
||||
}
|
||||
}
|
||||
|
||||
impl Cli {
|
||||
pub fn validate_socket(mut self) -> Self {
|
||||
if let Ok(path) = std::env::var("NOXIS_SOCKET_PATH") {
|
||||
self.socket = path;
|
||||
}
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ use thiserror::Error;
|
|||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum NoxisCliError {
|
||||
#[error("Can't find socket `{0}`. Error : {1}")]
|
||||
#[error("Can't find socket `{0}`. {1}")]
|
||||
NoxisDaemonMissing(String, String),
|
||||
#[error("Noxis CLI can't write any data to the Noxis-rs port. Check daemon and it's runtime!")]
|
||||
PortIsNotWritable,
|
||||
|
|
|
|||
|
|
@ -25,6 +25,6 @@ pub async fn try_send(cli: Cli) -> Result<()> {
|
|||
.await
|
||||
.map_err(|er| NoxisCliError::CliResponseReadError(er.to_string()))?;
|
||||
|
||||
println!("Received response: {}", String::from_utf8_lossy(&response));
|
||||
println!("{}", String::from_utf8_lossy(&response));
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -9,7 +9,8 @@ use anyhow::Result;
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()>{
|
||||
let cli = Cli::parse();
|
||||
dotenv::dotenv().ok();
|
||||
let cli = Cli::parse().validate_socket();
|
||||
try_send(cli).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use log::{error, info};
|
||||
use log::{error, info, warn};
|
||||
use tokio::net::{ UnixStream, UnixListener };
|
||||
use tokio::time::{sleep, Duration};
|
||||
use std::fs;
|
||||
|
|
@ -34,7 +34,7 @@ pub async fn init_cli_pipeline(params: Arc<PrebootParams>) -> anyhow::Result<()>
|
|||
match list.accept().await {
|
||||
Ok((socket, _)) => {
|
||||
// tokio::spawn();
|
||||
process_connection(socket).await;
|
||||
process_connection(socket, params.clone()).await;
|
||||
},
|
||||
Err(er) => {
|
||||
error!("Cannot poll connection to CLI due to {}", er);
|
||||
|
|
@ -64,7 +64,7 @@ pub async fn init_cli_pipeline(params: Arc<PrebootParams>) -> anyhow::Result<()>
|
|||
///
|
||||
/// *depends on* : `tokio::net::TcpStream`
|
||||
///
|
||||
async fn process_connection(mut stream: UnixStream) {
|
||||
async fn process_connection(mut stream: UnixStream, params: Arc<PrebootParams>) {
|
||||
let mut buf = vec![0; 1024];
|
||||
match stream.read(&mut buf).await {
|
||||
Ok(0) => {
|
||||
|
|
@ -76,9 +76,15 @@ async fn process_connection(mut stream: UnixStream) {
|
|||
match serde_json::from_slice::<Cli>(&buf) {
|
||||
Ok(cli) => {
|
||||
info!("Received CLI request: {:?}", cli);
|
||||
let response = "OK";
|
||||
if let Err(e) = stream.write_all(response.as_bytes()).await {
|
||||
error!("Failed to send response: {}", e);
|
||||
match process_cli_cmd(cli, params.clone()).await {
|
||||
Ok(response) => {
|
||||
if let Err(e) = stream.write_all(response.as_bytes()).await {
|
||||
error!("Failed to send response: {}", e);
|
||||
}
|
||||
},
|
||||
Err(er) => {
|
||||
error!("Can't send response from cli_pipeline: {}", er);
|
||||
},
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
|
|
@ -90,3 +96,27 @@ async fn process_connection(mut stream: UnixStream) {
|
|||
}
|
||||
let _ = stream.shutdown().await;
|
||||
}
|
||||
|
||||
|
||||
async fn process_cli_cmd(cli : Cli, params: Arc<PrebootParams>) -> anyhow::Result<String> {
|
||||
use noxis_cli::{Commands, ConfigAction};
|
||||
return match cli.command {
|
||||
Commands::Config(config) => {
|
||||
match config.action {
|
||||
ConfigAction::Show(env ) => {
|
||||
if env.is_env {
|
||||
Ok(serde_json::to_string_pretty(params.as_ref())?)
|
||||
} else {
|
||||
/* */
|
||||
Ok(String::from("Ok"))
|
||||
}
|
||||
},
|
||||
/* */
|
||||
_ => Ok(String::from("Ok"))
|
||||
}
|
||||
},
|
||||
/* */
|
||||
Commands::Status => Ok(String::from("Ok")),
|
||||
_ => Ok(String::from("Ok"))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ use dotenv::dotenv;
|
|||
/// noxis-rs ... --metrics none
|
||||
/// ```
|
||||
///
|
||||
#[derive(clap::ValueEnum, Debug, Clone)]
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub enum MetricsPrebootParams {
|
||||
Full,
|
||||
Full,
|
||||
System,
|
||||
Processes,
|
||||
Net,
|
||||
|
|
@ -177,7 +177,7 @@ impl std::fmt::Display for MetricsPrebootParams {
|
|||
/// export NOXIS_METRICS_MODE "full"
|
||||
/// ```
|
||||
///
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub struct PrebootParams {
|
||||
pub no_hostagent : bool,
|
||||
pub no_logs: bool,
|
||||
|
|
|
|||
Loading…
Reference in New Issue