feat(config): add EolRule struct for managing end-of-life rules

- introduce EolRule struct with fields for id, retention, labels, query, and command
- implement methods for creating new rules, setting retention, and adding labels
- add default implementation for EolRule
This commit is contained in:
Jeremiah Russell
2025-10-07 15:51:41 +01:00
committed by Jeremiah Russell
parent f63a0f888d
commit e77b372413

40
src/config/eol_rule.rs Normal file
View File

@@ -0,0 +1,40 @@
use serde::{Deserialize, Serialize};
use crate::{Retention, eol_cmd::EolCmd};
/// End of life rules
#[derive(Debug, Serialize, Deserialize, Default)]
pub(crate) struct EolRule {
id: usize,
retention: String,
labels: Vec<String>,
query: Option<String>,
command: String,
}
impl EolRule {
pub(crate) fn new(id: usize) -> Self {
EolRule {
id,
command: EolCmd::Trash.to_string(),
..Default::default()
}
}
pub(crate) fn set_retention(&mut self, value: Retention) -> &mut Self {
self.retention = value.age().to_string();
if value.generate_label() {
self.add_label(&value.age().label());
}
self
}
pub(crate) fn add_label(&mut self, value: &str) -> &mut Self {
self.labels.push(value.to_string());
self
}
pub(crate) fn id(&self) -> usize {
self.id
}
}