From 1754b64db14a1ea409779738a84d020fbb1ac79b Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Thu, 25 Jul 2024 20:01:46 -0400 Subject: Unify dns_name and dns_ttl into a "target" type, pass that around. --- src/ec2.rs | 44 ++++++-------------------------------------- 1 file changed, 6 insertions(+), 38 deletions(-) (limited to 'src/ec2.rs') diff --git a/src/ec2.rs b/src/ec2.rs index 998b98b..0457643 100644 --- a/src/ec2.rs +++ b/src/ec2.rs @@ -3,29 +3,24 @@ use std::collections::HashSet; use anyhow::Result; use aws_sdk_ec2 as ec2; use aws_sdk_ec2::types::Filter; -use aws_sdk_route53::types::{ResourceRecord, ResourceRecordSet, RrType}; -// Needed until try_collect is stable, see -use itertools::Itertools; -use trust_dns_proto::rr::Name; +use aws_sdk_route53::types::{ResourceRecordSet, RrType}; use crate::hashable::Hashable; +use crate::route53::Target; pub trait Ec2 { fn ec2(&self) -> &ec2::Client; } -pub async fn instance_proposal( +pub async fn asg_instances_proposal( aws_context: &C, + target: &Target, asg_name: &str, - dns_name: &Name, - dns_ttl: i64, live_instance_ids: &[String], ) -> Result>> where C: Ec2, { - assert!(dns_name.is_fqdn()); - // If there's nothing running, then (a) we don't need to ask AWS about // running instances, and (b) we can't anyways as the API call requires at // least one instance ID. Abort here. @@ -69,9 +64,8 @@ where } } - let dns_name = dns_name.to_ascii(); - let ip4_proposal = host_proposal(&dns_name, dns_ttl, RrType::A, ip4)?; - let ip6_proposal = host_proposal(&dns_name, dns_ttl, RrType::Aaaa, ip6)?; + let ip4_proposal = target.host_proposal(RrType::A, ip4)?; + let ip6_proposal = target.host_proposal(RrType::Aaaa, ip6)?; Ok(ip4_proposal .into_iter() @@ -79,29 +73,3 @@ where .map(Hashable::from) .collect()) } - -fn host_proposal( - dns_name: &str, - dns_ttl: i64, - rr_type: RrType, - addresses: HashSet>, -) -> Result> { - if addresses.is_empty() { - Ok(None) - } else { - let records = addresses - .into_iter() - .map(|address| address.into()) - .map(|address| ResourceRecord::builder().value(address).build()) - .try_collect()?; - - let record_set = ResourceRecordSet::builder() - .name(dns_name) - .r#type(rr_type) - .ttl(dns_ttl) - .set_resource_records(Some(records)) - .build()?; - - Ok(Some(record_set)) - } -} -- cgit v1.2.3