Compare commits
No commits in common. "d400318aadb4fc812ccaa8378390b0cbf5afa229" and "cc8c7f19bf6a9ba2ff77dad34aef271a119fc4ea" have entirely different histories.
d400318aad
...
cc8c7f19bf
|
|
@ -1,5 +1,4 @@
|
||||||
/target
|
/target
|
||||||
.idea
|
.idea
|
||||||
/.env
|
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
hagent_test.sock
|
hagent_test.sock
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "noxis-rs"
|
name = "noxis-rs"
|
||||||
version = "0.11.10"
|
version = "0.11.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
@ -17,4 +17,3 @@ serde_json = "1.0.118"
|
||||||
sysinfo = "0.32.0"
|
sysinfo = "0.32.0"
|
||||||
tokio = { version = "1.38.0", features = ["full", "time"] }
|
tokio = { version = "1.38.0", features = ["full", "time"] }
|
||||||
noxis-cli = { path = "../noxis-cli" }
|
noxis-cli = { path = "../noxis-cli" }
|
||||||
dotenv = "0.15.0"
|
|
||||||
|
|
|
||||||
|
|
@ -3,91 +3,9 @@
|
||||||
use anyhow::{Result, Ok, Error};
|
use anyhow::{Result, Ok, Error};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::env::var;
|
|
||||||
use dotenv::dotenv;
|
|
||||||
|
|
||||||
const SOCKET_PATH: &str = "/var/run/enode/hostagent.sock";
|
const SOCKET_PATH: &str = "/var/run/enode/hostagent.sock";
|
||||||
|
|
||||||
///
|
|
||||||
enum EnvVars {
|
|
||||||
NoxisNoHagent,
|
|
||||||
NoxisNoLogs,
|
|
||||||
NoxisRefreshLogs,
|
|
||||||
NoxisNoRemoteConfig,
|
|
||||||
NoxisNoConfigSub,
|
|
||||||
NoxisSocketPath,
|
|
||||||
NoxisLogTo,
|
|
||||||
NoxisRemoteServerUrl,
|
|
||||||
NoxisConfig,
|
|
||||||
NoxisMetrics,
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
impl std::fmt::Display for EnvVars {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
||||||
match self {
|
|
||||||
EnvVars::NoxisNoHagent => write!(f, "NOXIS_NO_HAGENT"),
|
|
||||||
EnvVars::NoxisNoLogs => write!(f, "NOXIS_NO_LOGS"),
|
|
||||||
EnvVars::NoxisRefreshLogs => write!(f, "NOXIS_REFRESH_LOGS"),
|
|
||||||
EnvVars::NoxisNoRemoteConfig => write!(f, "NOXIS_NO_REMOTE_CONFIG"),
|
|
||||||
EnvVars::NoxisNoConfigSub => write!(f, "NOXIS_NO_CONFIG_SUB"),
|
|
||||||
EnvVars::NoxisSocketPath => write!(f, "NOXIS_SOCKET_PATH"),
|
|
||||||
EnvVars::NoxisLogTo => write!(f, "NOXIS_LOG_TO"),
|
|
||||||
EnvVars::NoxisRemoteServerUrl => write!(f, "NOXIS_REMOTE_SERVER_URL"),
|
|
||||||
EnvVars::NoxisConfig => write!(f, "NOXIS_CONFIG"),
|
|
||||||
EnvVars::NoxisMetrics => write!(f, "NOXIS_METRICS"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
impl<'a> EnvVars {
|
|
||||||
// Default trait func is not satisfying this issue
|
|
||||||
fn default(self) -> &'a str {
|
|
||||||
match self {
|
|
||||||
EnvVars::NoxisNoHagent => "false",
|
|
||||||
EnvVars::NoxisNoLogs => "false",
|
|
||||||
EnvVars::NoxisRefreshLogs => "false",
|
|
||||||
EnvVars::NoxisNoRemoteConfig => "false",
|
|
||||||
EnvVars::NoxisNoConfigSub => "false",
|
|
||||||
EnvVars::NoxisSocketPath => "/var/run/enode/hostagent.sock",
|
|
||||||
EnvVars::NoxisLogTo => "./",
|
|
||||||
EnvVars::NoxisRemoteServerUrl => "localhost",
|
|
||||||
EnvVars::NoxisConfig => "./settings.json",
|
|
||||||
EnvVars::NoxisMetrics => "full",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn process_env_var(self, preboot_value: &str) {
|
|
||||||
// let default = self.default();
|
|
||||||
match var(self.to_string()) {
|
|
||||||
std::result::Result::Ok(val) => {
|
|
||||||
if val != preboot_value {
|
|
||||||
std::env::set_var(self.to_string(), self.default());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(_) => {
|
|
||||||
std::env::set_var(self.to_string(), preboot_value);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn setup(preboot: &PrebootParams) {
|
|
||||||
// setup default if not exists
|
|
||||||
// check values and save preboot states in env vars if not equal
|
|
||||||
|
|
||||||
Self::NoxisNoHagent.process_env_var(&preboot.no_hostagent.to_string());
|
|
||||||
Self::NoxisNoLogs.process_env_var(&preboot.no_logs.to_string());
|
|
||||||
Self::NoxisRefreshLogs.process_env_var(&preboot.refresh_logs.to_string());
|
|
||||||
Self::NoxisNoRemoteConfig.process_env_var(&preboot.no_remote_config.to_string());
|
|
||||||
Self::NoxisNoConfigSub.process_env_var(&preboot.no_sub.to_string());
|
|
||||||
Self::NoxisSocketPath.process_env_var(preboot.socket_path.to_str().unwrap());
|
|
||||||
Self::NoxisLogTo.process_env_var(preboot.log_to.to_str().unwrap());
|
|
||||||
Self::NoxisRemoteServerUrl.process_env_var(&preboot.remote_server_url);
|
|
||||||
Self::NoxisConfig.process_env_var(preboot.config.to_str().unwrap());
|
|
||||||
Self::NoxisMetrics.process_env_var(&preboot.metrics.to_string());
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// # Enum `MetricsPrebootParams`
|
/// # Enum `MetricsPrebootParams`
|
||||||
/// ## for setting up metrics mode as preboot param from command prompt
|
/// ## for setting up metrics mode as preboot param from command prompt
|
||||||
///
|
///
|
||||||
|
|
@ -269,7 +187,6 @@ pub struct PrebootParams {
|
||||||
/// ## to enable validation mechanism
|
/// ## to enable validation mechanism
|
||||||
impl PrebootParams {
|
impl PrebootParams {
|
||||||
pub fn validate(mut self) -> Result<Self> {
|
pub fn validate(mut self) -> Result<Self> {
|
||||||
dotenv().ok();
|
|
||||||
if !self.socket_path.exists() && !self.no_hostagent {
|
if !self.socket_path.exists() && !self.no_hostagent {
|
||||||
if self.socket_path.to_string_lossy() == SOCKET_PATH {
|
if self.socket_path.to_string_lossy() == SOCKET_PATH {
|
||||||
self.no_hostagent = true;
|
self.no_hostagent = true;
|
||||||
|
|
@ -294,15 +211,10 @@ impl PrebootParams {
|
||||||
// existing sock file
|
// existing sock file
|
||||||
if !self.config.exists() {
|
if !self.config.exists() {
|
||||||
eprintln!("Error: Invalid character in config file. Config path was set to default");
|
eprintln!("Error: Invalid character in config file. Config path was set to default");
|
||||||
let config = PathBuf::from("/etc/settings.json");
|
|
||||||
if !config.exists() && self.no_remote_config {
|
|
||||||
return Err(Error::msg("Noxis cannot run without config. Create local config or enable remote-config mechanism"));
|
|
||||||
}
|
|
||||||
self.config = PathBuf::from("settings.json");
|
self.config = PathBuf::from("settings.json");
|
||||||
// return Err(Error::msg("Local Config Not Found or Noxis can't read it. Cannot start"));
|
// return Err(Error::msg("Local Config Not Found or Noxis can't read it. Cannot start"));
|
||||||
}
|
}
|
||||||
// redis server check
|
// redis server check
|
||||||
EnvVars::setup(&self);
|
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue