get local config using cli
parent
92aa6f5b66
commit
5c94e366eb
|
|
@ -5,6 +5,7 @@ use std::fs;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::io::{ AsyncWriteExt, AsyncReadExt};
|
use tokio::io::{ AsyncWriteExt, AsyncReadExt};
|
||||||
use noxis_cli::Cli;
|
use noxis_cli::Cli;
|
||||||
|
use super::structs::Processes;
|
||||||
|
|
||||||
use super::preboot::PrebootParams;
|
use super::preboot::PrebootParams;
|
||||||
|
|
||||||
|
|
@ -21,7 +22,7 @@ use super::preboot::PrebootParams;
|
||||||
///
|
///
|
||||||
/// *depends on* : -
|
/// *depends on* : -
|
||||||
///
|
///
|
||||||
pub async fn init_cli_pipeline(params: Arc<PrebootParams>) -> anyhow::Result<()> {
|
pub async fn init_cli_pipeline(params: Arc<PrebootParams>, config : Arc<Processes>) -> anyhow::Result<()> {
|
||||||
let socket_path = ¶ms.self_socket;
|
let socket_path = ¶ms.self_socket;
|
||||||
let _ = fs::remove_file(socket_path);
|
let _ = fs::remove_file(socket_path);
|
||||||
|
|
||||||
|
|
@ -33,8 +34,7 @@ pub async fn init_cli_pipeline(params: Arc<PrebootParams>) -> anyhow::Result<()>
|
||||||
loop {
|
loop {
|
||||||
match list.accept().await {
|
match list.accept().await {
|
||||||
Ok((socket, _)) => {
|
Ok((socket, _)) => {
|
||||||
// tokio::spawn();
|
process_connection(socket, params.clone(), config.clone()).await;
|
||||||
process_connection(socket, params.clone()).await;
|
|
||||||
},
|
},
|
||||||
Err(er) => {
|
Err(er) => {
|
||||||
error!("Cannot poll connection to CLI due to {}", 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`
|
/// *depends on* : `tokio::net::TcpStream`
|
||||||
///
|
///
|
||||||
async fn process_connection(mut stream: UnixStream, params: Arc<PrebootParams>) {
|
async fn process_connection(mut stream: UnixStream, params: Arc<PrebootParams>, config : Arc<Processes>) {
|
||||||
let mut buf = vec![0; 1024];
|
let mut buf = vec![0; 1024];
|
||||||
match stream.read(&mut buf).await {
|
match stream.read(&mut buf).await {
|
||||||
Ok(0) => {
|
Ok(0) => {
|
||||||
|
|
@ -76,7 +76,7 @@ async fn process_connection(mut stream: UnixStream, params: Arc<PrebootParams>)
|
||||||
match serde_json::from_slice::<Cli>(&buf) {
|
match serde_json::from_slice::<Cli>(&buf) {
|
||||||
Ok(cli) => {
|
Ok(cli) => {
|
||||||
info!("Received CLI request: {:?}", cli);
|
info!("Received CLI request: {:?}", cli);
|
||||||
match process_cli_cmd(cli, params.clone()).await {
|
match process_cli_cmd(cli, params.clone(), config).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
if let Err(e) = stream.write_all(response.as_bytes()).await {
|
if let Err(e) = stream.write_all(response.as_bytes()).await {
|
||||||
error!("Failed to send response: {}", e);
|
error!("Failed to send response: {}", e);
|
||||||
|
|
@ -98,7 +98,7 @@ async fn process_connection(mut stream: UnixStream, params: Arc<PrebootParams>)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async fn process_cli_cmd(cli : Cli, params: Arc<PrebootParams>) -> anyhow::Result<String> {
|
async fn process_cli_cmd(cli : Cli, params: Arc<PrebootParams>, global_config : Arc<Processes>) -> anyhow::Result<String> {
|
||||||
use noxis_cli::{Commands, ConfigAction};
|
use noxis_cli::{Commands, ConfigAction};
|
||||||
return match cli.command {
|
return match cli.command {
|
||||||
Commands::Config(config) => {
|
Commands::Config(config) => {
|
||||||
|
|
@ -108,7 +108,7 @@ async fn process_cli_cmd(cli : Cli, params: Arc<PrebootParams>) -> anyhow::Resul
|
||||||
Ok(serde_json::to_string_pretty(params.as_ref())?)
|
Ok(serde_json::to_string_pretty(params.as_ref())?)
|
||||||
} else {
|
} else {
|
||||||
/* */
|
/* */
|
||||||
Ok(String::from("Ok"))
|
Ok(serde_json::to_string_pretty(global_config.as_ref())?)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/* */
|
/* */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue