summaryrefslogtreecommitdiff
path: root/src/ec2.rs
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-07-24 19:26:45 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-07-24 19:26:45 -0400
commite872bcdc978283b45da22a4de5ed195dce613a71 (patch)
tree6a7c7813e52e5c546cc6f187e12b5f5bdca42f6e /src/ec2.rs
parent77642df3e17b5272617c48832f37b7ab3dd6f27b (diff)
Upgrade AWS libraries.
This comes with some substantial removals, because the AWS libs no longer treat every last field as optional when it's inappropriate to do so. Hooray!
Diffstat (limited to 'src/ec2.rs')
-rw-r--r--src/ec2.rs23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/ec2.rs b/src/ec2.rs
index 67a098c..44719ed 100644
--- a/src/ec2.rs
+++ b/src/ec2.rs
@@ -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))
}
}