WIP: feat: implementation for opnsense os-node_exporter #173

Draft
wjro wants to merge 3 commits from feat/install_opnsense_node_exporter into master
Showing only changes of commit 5af13800b7 - Show all commits

View File

@ -20,21 +20,20 @@ impl<'a> NodeExporterConfig<'a> {
pub fn get_full_config(&self) -> &Option<NodeExporter> {
&self.opnsense.opnsense.node_exporter
}
fn with_node_exporter<F, R>(&mut self, f: F) -> R
wjro marked this conversation as resolved Outdated

white line missing

white line missing
fn with_node_exporter<F, R>(&mut self, f: F) -> Result<R, &'static str>
where
F: FnOnce(&mut NodeExporter) -> R,
{
match &mut self.opnsense.opnsense.node_exporter.as_mut() {
Some(node_exporter) => f(node_exporter),
None => unimplemented!(
"
node exporter is not yet installed"
),
Some(node_exporter) => Ok(f(node_exporter)),
None => Err("node exporter is not yet installed"),
wjro marked this conversation as resolved Outdated

is it expected to have a line return here?

is it expected to have a line return here?
}
}
pub fn enable(&mut self, enabled: bool) {
pub fn enable(&mut self, enabled: bool) -> Result<(), &'static str> {
self.with_node_exporter(|node_exporter| node_exporter.enabled = enabled as u8)
.map(|_| ())
}
pub async fn reload_restart(&self) -> Result<(), Error> {