Skip to content

Commit

Permalink
Make config:modules optional in the configuration, defaulting to /usr…
Browse files Browse the repository at this point in the history
…/share/sysinspect/modules
  • Loading branch information
isbm committed Nov 19, 2024
1 parent 9dd49ec commit 5faa8e4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions libsysinspect/src/cfg/mmconf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub static DEFAULT_FILESERVER_PORT: u32 = 4201;
// Default directories
pub static DEFAULT_SOCKET: &str = "/var/run/sysinspect-master.socket";
pub static DEFAULT_SYSINSPECT_ROOT: &str = "/etc/sysinspect";
pub static DEFAULT_MODULES_ROOT: &str = "/usr/share/sysinspect/modules";

// All directories are relative to the sysinspect root
pub static CFG_MINION_KEYS: &str = "minion-keys";
Expand Down
8 changes: 4 additions & 4 deletions libsysinspect/src/intp/conf.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{util, SysinspectError};
use crate::{cfg::mmconf::DEFAULT_MODULES_ROOT, util, SysinspectError};
use serde::{Deserialize, Serialize};
use serde_yaml::Value;
use std::{collections::HashMap, path::PathBuf};
Expand Down Expand Up @@ -69,7 +69,7 @@ impl EventConfig {
/// The entire config
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct Config {
modules: PathBuf,
modules: Option<PathBuf>,

// EventId to config, added later
events: Option<HashMap<String, EventConfig>>,
Expand All @@ -87,7 +87,7 @@ impl Config {
/// Get module from the namespace
pub fn get_module(&self, namespace: &str) -> Result<PathBuf, SysinspectError> {
// Fool-proof cleanup, likely a bad idea
let modpath = self.modules.join(
let modpath = &self.modules.to_owned().unwrap_or(PathBuf::from(DEFAULT_MODULES_ROOT)).join(
namespace
.trim_start_matches('.')
.trim_end_matches('.')
Expand All @@ -102,7 +102,7 @@ impl Config {
return Err(SysinspectError::ModuleError(format!("Module \"{}\" was not found at {:?}", namespace, modpath)));
}

Ok(modpath)
Ok(modpath.to_owned())
}

/// Set events config
Expand Down

0 comments on commit 5faa8e4

Please sign in to comment.