config refactor
parent
58dedc1adf
commit
7efdfb39ba
|
|
@ -1,7 +1,6 @@
|
|||
// mod to communicate with api-grub config file
|
||||
// 1) check changes in unix-socket
|
||||
// 2) save changes in local config file
|
||||
use integr_structs::api::ApiConfigV2;
|
||||
use anyhow::{Error, Ok, Result};
|
||||
use log::{info, warn, error};
|
||||
use std::{fs, path::Path};
|
||||
|
|
@ -15,19 +14,9 @@ use integr_structs::api::v3::Config;
|
|||
const CONFIG_PATH: &str = "config_api.json";
|
||||
const SOCKET_PATH: &str = "api-grub.sock";
|
||||
|
||||
// todo! rewrite to use current_exe
|
||||
// TODO: rewrite to use current_exe
|
||||
pub async fn pull_local_config() -> Result<Config> {
|
||||
// let conf_path = std::env::current_exe()?;
|
||||
let path = Path::new(CONFIG_PATH);
|
||||
// return match conf_path.parent() {
|
||||
// Some(dir) => {
|
||||
// let config: ApiConfig = from_str(
|
||||
// &fs::read_to_string(dir.join(CONFIG_PATH))?
|
||||
// )?;
|
||||
// Ok(config)
|
||||
// },
|
||||
// None => Err(Error::msg("No local conf was found"))
|
||||
// }
|
||||
if path.exists() && path.is_file() {
|
||||
let config: Config = from_str(
|
||||
&fs::read_to_string(CONFIG_PATH)?
|
||||
|
|
@ -39,14 +28,13 @@ pub async fn pull_local_config() -> Result<Config> {
|
|||
}
|
||||
|
||||
// for config pulling
|
||||
// ++++ reader to channel
|
||||
pub async fn init_config_grub_mechanism(tx: &Sender<Config>) -> Result<()> {
|
||||
info!("Initializing Unix-Socket listening for pulling new configs...");
|
||||
let server = init_unix_listener().await?;
|
||||
//
|
||||
|
||||
info!("Listening Unix-Socket...");
|
||||
let mut buffer = String::new();
|
||||
//
|
||||
|
||||
loop {
|
||||
if let stdOk((mut stream, _)) = server.accept().await {
|
||||
if let Err(er) = stream.read_to_string(&mut buffer).await {
|
||||
|
|
|
|||
Loading…
Reference in New Issue