From 310f78c2f4921089bfb90011a244b71df403129e Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Wed, 24 Jul 2024 21:56:21 -0400 Subject: Refactor converge.rs to make the overall flow clearer. This entails moving a bunch of things into more appropriate modules, as well. --- src/dns.rs | 52 +--------------------------------------------------- 1 file changed, 1 insertion(+), 51 deletions(-) (limited to 'src/dns.rs') diff --git a/src/dns.rs b/src/dns.rs index 224d56e..376c6c6 100644 --- a/src/dns.rs +++ b/src/dns.rs @@ -1,56 +1,6 @@ -use std::convert::TryFrom; -use std::fmt::Debug; - -use anyhow::{anyhow, Result}; -use aws_sdk_autoscaling::types::{AutoScalingGroup, Instance, LifecycleState}; +use anyhow::Result; use trust_dns_proto::rr::Name; -#[derive(Debug)] -pub struct AutoScalingGroupConfig { - pub name: String, - pub live_instance_ids: Vec, -} - -impl AutoScalingGroupConfig { - fn live_instance_ids<'a>(instances: impl IntoIterator) -> Vec { - instances - .into_iter() - .filter(|instance| match instance.lifecycle_state() { - // See - // - // Include pending instances so that they can obtain certs, etc. - Some(LifecycleState::Pending) => true, - Some(LifecycleState::PendingWait) => true, - Some(LifecycleState::PendingProceed) => true, - Some(LifecycleState::InService) => true, - _ => false, - }) - .flat_map(|instance| instance.instance_id()) - .map(ToOwned::to_owned) - .collect() - } -} - -impl TryFrom<&AutoScalingGroup> for AutoScalingGroupConfig { - type Error = anyhow::Error; - - fn try_from(autoscaling_group: &AutoScalingGroup) -> Result { - let name = autoscaling_group - .auto_scaling_group_name() - .ok_or(anyhow!("Autoscaling group returned from AWS with no name"))? - .to_owned(); - - let instances = autoscaling_group.instances(); - - let live_instance_ids = Self::live_instance_ids(instances); - - Ok(Self { - name, - live_instance_ids, - }) - } -} - pub fn suffixes(mut name: Name) -> Vec { let mut names = Vec::new(); -- cgit v1.2.3