♻️ refactor(config): enhance EolRule for label management
- migrate labels from Vec to BTreeSet for uniqueness and order - add `remove_label` function to remove specific labels - change `labels()` function return type from `&Vec<String>` to `Vec<String>` - implement `Clone` trait for `EolRule`
This commit is contained in:
committed by
Jeremiah Russell
parent
80c8bbc863
commit
6df0ef6536
@@ -1,15 +1,15 @@
|
|||||||
use std::fmt;
|
use std::{collections::BTreeSet, fmt};
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{Retention, eol_cmd::EolAction};
|
use crate::{Retention, eol_cmd::EolAction};
|
||||||
|
|
||||||
/// End of life rules
|
/// End of life rules
|
||||||
#[derive(Debug, Serialize, Deserialize, Default)]
|
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
|
||||||
pub(crate) struct EolRule {
|
pub(crate) struct EolRule {
|
||||||
id: usize,
|
id: usize,
|
||||||
retention: String,
|
retention: String,
|
||||||
labels: Vec<String>,
|
labels: BTreeSet<String>,
|
||||||
query: Option<String>,
|
query: Option<String>,
|
||||||
action: String,
|
action: String,
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,11 @@ impl fmt::Display for EolRule {
|
|||||||
f,
|
f,
|
||||||
"Rule #{} is active on {} and {action} is {count} {period} old.",
|
"Rule #{} is active on {} and {action} is {count} {period} old.",
|
||||||
self.id,
|
self.id,
|
||||||
self.labels.join(", ")
|
self.labels
|
||||||
|
.iter()
|
||||||
|
.map(|i| i.to_string())
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join(", ")
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
write!(f, "Complete retention rule not set.")
|
write!(f, "Complete retention rule not set.")
|
||||||
@@ -72,16 +76,20 @@ impl EolRule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn add_label(&mut self, value: &str) -> &mut Self {
|
pub(crate) fn add_label(&mut self, value: &str) -> &mut Self {
|
||||||
self.labels.push(value.to_string());
|
self.labels.insert(value.to_string());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn remove_label(&mut self, value: &str) {
|
||||||
|
self.labels.remove(value);
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn id(&self) -> usize {
|
pub(crate) fn id(&self) -> usize {
|
||||||
self.id
|
self.id
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn labels(&self) -> &Vec<String> {
|
pub(crate) fn labels(&self) -> Vec<String> {
|
||||||
&self.labels
|
self.labels.iter().map(|i| i.to_string()).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn set_command(&mut self, value: EolAction) -> &mut Self {
|
pub(crate) fn set_command(&mut self, value: EolAction) -> &mut Self {
|
||||||
|
|||||||
Reference in New Issue
Block a user