Skip to content

Commit

Permalink
chore: new velocity enforcement builder
Browse files Browse the repository at this point in the history
  • Loading branch information
thevaibhav-dixit committed Oct 14, 2024
1 parent ddbf469 commit 20d2279
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
16 changes: 14 additions & 2 deletions cala-ledger/src/velocity/control/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub struct NewVelocityControl {
#[builder(setter(into))]
description: String,
#[builder(setter(into), default)]
enforcement: VelocityEnforcement,
enforcement: NewVelocityEnforcement,
#[builder(setter(strip_option, into), default)]
condition: Option<String>,
}
Expand All @@ -93,7 +93,7 @@ impl NewVelocityControl {
id: self.id,
name: self.name,
description: self.description,
enforcement: self.enforcement,
enforcement: self.enforcement.action.into(),
condition: self
.condition
.map(|expr| CelExpression::try_from(expr).expect("already validated")),
Expand All @@ -116,3 +116,15 @@ fn validate_optional_expression(expr: &Option<Option<String>>) -> Result<(), Str
}
Ok(())
}

#[derive(Builder, Debug, Clone, Default)]
pub struct NewVelocityEnforcement {
#[builder(setter(into), default)]
pub(super) action: VelocityEnforcementAction,
}

impl NewVelocityEnforcement {
pub fn builder() -> NewVelocityEnforcementBuilder {
NewVelocityEnforcementBuilder::default()
}
}
7 changes: 7 additions & 0 deletions cala-server/src/graphql/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,13 @@ impl<E: MutationExtensionMarker> CoreMutation<E> {
new_velocity_control_builder.condition(condition);
}

let mut new_velocity_enforcement_builder =
cala_ledger::velocity::NewVelocityEnforcement::builder();
new_velocity_enforcement_builder.action(input.enforcement.velocity_enforcement_action);
let new_velocity_enforcement = new_velocity_enforcement_builder.build()?;

new_velocity_control_builder.enforcement(new_velocity_enforcement);

let new_velocity_control = new_velocity_control_builder.build()?;
let velocity_control = app
.ledger()
Expand Down

0 comments on commit 20d2279

Please sign in to comment.