use std::path::PathBuf;
use crate::{
config::Config,
container::{Container, ContainerManager, DEFAULT_EVEBOX_IMAGE, DEFAULT_SURICATA_IMAGE},
};
#[derive(Clone)]
pub(crate) struct Context {
pub root: PathBuf,
pub config: Config,
pub manager: ContainerManager,
pub suricata_image: String,
pub evebox_image: String,
}
impl Context {
pub(crate) fn new(config: Config, root: PathBuf, manager: ContainerManager) -> Self {
let suricata_image = image_name(&config, Container::Suricata);
let evebox_image = image_name(&config, Container::EveBox);
Self {
root,
config,
manager,
suricata_image,
evebox_image,
}
}
pub(crate) fn image_name(&self, container: Container) -> String {
image_name(&self.config, container)
}
pub fn config_dir(&self) -> PathBuf {
self.root.join("config")
}
pub fn data_dir(&self) -> PathBuf {
self.root.join("data")
}
}
pub(crate) fn image_name(config: &Config, container: Container) -> String {
match container {
Container::Suricata => config
.suricata
.image
.as_deref()
.unwrap_or(DEFAULT_SURICATA_IMAGE)
.to_string(),
Container::EveBox => config
.evebox_server
.image
.as_deref()
.unwrap_or(DEFAULT_EVEBOX_IMAGE)
.to_string(),
}
}