diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-07-24 21:56:21 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-07-24 21:56:21 -0400 |
| commit | 310f78c2f4921089bfb90011a244b71df403129e (patch) | |
| tree | 639c3ce2423af54fc6251923729fda75c22e520d /src/dns.rs | |
| parent | 3ce81264fa4e87e4d26b3966778879fccce33998 (diff) | |
Refactor converge.rs to make the overall flow clearer.
This entails moving a bunch of things into more appropriate modules, as well.
Diffstat (limited to 'src/dns.rs')
| -rw-r--r-- | src/dns.rs | 52 |
1 files changed, 1 insertions, 51 deletions
@@ -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<String>, -} - -impl AutoScalingGroupConfig { - fn live_instance_ids<'a>(instances: impl IntoIterator<Item = &'a Instance>) -> Vec<String> { - instances - .into_iter() - .filter(|instance| match instance.lifecycle_state() { - // See <https://docs.aws.amazon.com/autoscaling/ec2/userguide/AutoScalingGroupLifecycle.html> - // - // 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<Self> { - 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<Name> { let mut names = Vec::new(); |
