use crate::{
PolicyError,
PolicyLocation,
RedactionFloor,
RedactionRules,
policy::RedactionRulesBuilder,
};
#[derive(Debug, Clone)]
pub(super) struct ContextRulesBuilder {
pub(super) rules: RedactionRulesBuilder,
pub(super) floor: Option<RedactionFloor>,
}
impl ContextRulesBuilder {
pub(super) fn empty(location: PolicyLocation) -> Self {
Self {
rules: RedactionRulesBuilder::empty(location),
floor: None,
}
}
pub(super) fn from_rules(
rules: &RedactionRules,
location: PolicyLocation,
) -> Self {
Self {
rules: RedactionRulesBuilder::from_inner(
&rules.clone_application(),
location,
),
floor: rules.floor().cloned(),
}
}
pub(super) fn with_floor(&mut self, floor: RedactionFloor) {
self.floor = Some(floor);
}
pub(super) fn disable_floor(&mut self) {
self.floor = None;
}
pub(super) fn build(self) -> Result<RedactionRules, PolicyError> {
Ok(RedactionRules::new(self.rules.build_inner()?, self.floor))
}
}