diff options
Diffstat (limited to 'src/ec2.rs')
| -rw-r--r-- | src/ec2.rs | 23 |
1 files changed, 12 insertions, 11 deletions
@@ -4,7 +4,8 @@ use anyhow::Result; use aws_sdk_ec2 as ec2; use aws_sdk_ec2::types::Filter; use aws_sdk_route53::types::{ResourceRecord, ResourceRecordSet, RrType}; -use futures::stream::TryStreamExt; +// Needed until try_collect is stable, see <https://github.com/rust-lang/rust/issues/94047> +use itertools::Itertools; use trust_dns_proto::rr::Name; use crate::dns::absolute; @@ -49,15 +50,15 @@ where .send(); while let Some(reservation) = instances_paginator.try_next().await? { - let instances = reservation.instances().unwrap_or(&[]); + let instances = reservation.instances(); for instance in instances { // Mild abuse of the fact that optional values are also iterable apex_ip4.extend(instance.public_ip_address().map(String::from)); - let instance_interfaces = instance.network_interfaces().unwrap_or(&[]); + let instance_interfaces = instance.network_interfaces(); let instance_ip6: Vec<_> = instance_interfaces .iter() - .flat_map(|interface| interface.ipv6_addresses().unwrap_or(&[])) + .flat_map(|interface| interface.ipv6_addresses()) // Flatmap here to drop the None values, unwrap the Some values .flat_map(|ipv6| ipv6.ipv6_address()) .to_owned() @@ -70,8 +71,8 @@ where let apex_hostname = absolute(dns_suffix.clone())?; let apex_hostname = apex_hostname.to_ascii(); - let apex_ip4_recordset = apex_recordset(&apex_hostname, dns_ttl, RrType::A, apex_ip4); - let apex_ip6_recordset = apex_recordset(&apex_hostname, dns_ttl, RrType::Aaaa, apex_ip6); + let apex_ip4_recordset = apex_recordset(&apex_hostname, dns_ttl, RrType::A, apex_ip4)?; + let apex_ip6_recordset = apex_recordset(&apex_hostname, dns_ttl, RrType::Aaaa, apex_ip6)?; Ok(apex_ip4_recordset .into_iter() @@ -85,23 +86,23 @@ fn apex_recordset( dns_ttl: i64, rr_type: RrType, addresses: HashSet<impl Into<String>>, -) -> Option<ResourceRecordSet> { +) -> Result<Option<ResourceRecordSet>> { if addresses.is_empty() { - None + Ok(None) } else { let records = addresses .into_iter() .map(|address| address.into()) .map(|address| ResourceRecord::builder().value(address).build()) - .collect(); + .try_collect()?; let record_set = ResourceRecordSet::builder() .name(apex_hostname) .r#type(rr_type) .ttl(dns_ttl) .set_resource_records(Some(records)) - .build(); + .build()?; - Some(record_set) + Ok(Some(record_set)) } } |
