diff options
Diffstat (limited to 'src/apply.rs')
| -rw-r--r-- | src/apply.rs | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/src/apply.rs b/src/apply.rs index e0f3ff2..bf8373f 100644 --- a/src/apply.rs +++ b/src/apply.rs @@ -7,51 +7,57 @@ use itertools::Itertools; use crate::route53::{ResourceRecordSet, Route53}; +#[derive(Debug)] +pub struct Transaction<T> { + pub zone_id: String, + pub changes: Changes<T>, +} + +#[derive(Debug)] +pub struct Changes<T> { + pub remove: T, + pub insert: T, +} + pub enum ApplyMode { DryRun, Apply, } impl ApplyMode { - pub async fn apply<C, R>( - &self, - aws_context: &C, - zone_id: &str, - remove_records: R, - insert_records: R, - ) -> Result<()> + pub async fn apply<C, R>(&self, aws_context: &C, transaction: Transaction<R>) -> Result<()> where C: Route53, R: IntoIterator<Item = ResourceRecordSet> + Debug, { match self { - ApplyMode::DryRun => dry_run(zone_id, remove_records, insert_records).await, - ApplyMode::Apply => apply(aws_context, zone_id, remove_records, insert_records).await, + ApplyMode::DryRun => dry_run(transaction).await, + ApplyMode::Apply => apply(aws_context, transaction).await, } } } -async fn dry_run<R>(zone_id: &str, remove_records: R, insert_records: R) -> Result<()> +async fn dry_run<R>(transaction: Transaction<R>) -> Result<()> where R: IntoIterator<Item = ResourceRecordSet> + Debug, { - println!("ZONE: {}", zone_id); - println!("REMOVE: {:#?}", remove_records); - println!("INSERT: {:#?}", insert_records); + println!("ZONE: {}", transaction.zone_id); + println!("REMOVE: {:#?}", transaction.changes.remove); + println!("INSERT: {:#?}", transaction.changes.insert); Ok(()) } -async fn apply<C, R>( - aws_context: &C, - zone_id: &str, - remove_records: R, - insert_records: R, -) -> Result<()> +async fn apply<C, R>(aws_context: &C, transaction: Transaction<R>) -> Result<()> where C: Route53, R: IntoIterator<Item = ResourceRecordSet>, { + let Changes { + remove: remove_records, + insert: insert_records, + } = transaction.changes; + let remove_records = remove_records.into_iter().map(|record| { Change::builder() .action(ChangeAction::Delete) // <-- @@ -74,7 +80,7 @@ where aws_context .route53() .change_resource_record_sets() - .hosted_zone_id(zone_id) + .hosted_zone_id(transaction.zone_id) .change_batch(change_batch) .send() .await?; |
