diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-07-24 19:26:45 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-07-24 19:26:45 -0400 |
| commit | e872bcdc978283b45da22a4de5ed195dce613a71 (patch) | |
| tree | 6a7c7813e52e5c546cc6f187e12b5f5bdca42f6e /src | |
| parent | 77642df3e17b5272617c48832f37b7ab3dd6f27b (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')
| -rw-r--r-- | src/apply.rs | 6 | ||||
| -rw-r--r-- | src/autoscaling.rs | 2 | ||||
| -rw-r--r-- | src/aws_context.rs | 6 | ||||
| -rw-r--r-- | src/converge.rs | 6 | ||||
| -rw-r--r-- | src/dns.rs | 2 | ||||
| -rw-r--r-- | src/ec2.rs | 23 | ||||
| -rw-r--r-- | src/route53.rs | 21 |
7 files changed, 30 insertions, 36 deletions
diff --git a/src/apply.rs b/src/apply.rs index abf579f..85c34d7 100644 --- a/src/apply.rs +++ b/src/apply.rs @@ -1,5 +1,7 @@ use anyhow::Result; use aws_sdk_route53::types::{Change, ChangeAction, ChangeBatch, ResourceRecordSet}; +// Needed until try_collect is stable, see <https://github.com/rust-lang/rust/issues/94047> +use itertools::Itertools; use crate::route53::Route53; @@ -67,11 +69,11 @@ where .build() }); - let change_records: Vec<_> = remove_records.chain(insert_records).collect(); + let change_records: Vec<_> = remove_records.chain(insert_records).try_collect()?; if !change_records.is_empty() { let change_batch = ChangeBatch::builder() .set_changes(Some(change_records)) - .build(); + .build()?; aws_context .route53() diff --git a/src/autoscaling.rs b/src/autoscaling.rs index 81b9961..327a4f7 100644 --- a/src/autoscaling.rs +++ b/src/autoscaling.rs @@ -19,7 +19,7 @@ where .send() .await?; - let auto_scaling_groups = asg_resp.auto_scaling_groups().unwrap_or(&[]); + let auto_scaling_groups = asg_resp.auto_scaling_groups(); let auto_scaling_group = auto_scaling_groups .iter() .map(ToOwned::to_owned) diff --git a/src/aws_context.rs b/src/aws_context.rs index 2eff941..8f1ae88 100644 --- a/src/aws_context.rs +++ b/src/aws_context.rs @@ -1,7 +1,7 @@ +use aws_config::{BehaviorVersion, SdkConfig}; use aws_sdk_autoscaling as asg; use aws_sdk_ec2 as ec2; use aws_sdk_route53 as route53; -use aws_types::SdkConfig; use crate::autoscaling::AutoScaling; use crate::ec2::Ec2; @@ -15,7 +15,9 @@ pub struct AwsContext { impl AwsContext { pub async fn from_env() -> Self { - let config = aws_config::from_env().load().await; + let config = aws_config::defaults(BehaviorVersion::v2024_03_28()) + .load() + .await; Self::new(&config) } diff --git a/src/converge.rs b/src/converge.rs index 8846aec..e79ac06 100644 --- a/src/converge.rs +++ b/src/converge.rs @@ -1,6 +1,6 @@ use std::fmt::Debug; -use anyhow::{anyhow, Result}; +use anyhow::Result; use aws_sdk_autoscaling::types::AutoScalingGroup; use aws_sdk_route53::types::ResourceRecordSet; use futures::try_join; @@ -34,9 +34,7 @@ where } = AutoScalingGroupConfig::try_from(auto_scaling_group)?; let zone = zone_for_domain(aws_context, dns_name).await?; - let zone_id = zone - .id() - .ok_or(anyhow!("No ID for hosted zone for name: {}", dns_name))?; + let zone_id = zone.id(); let (intended_records, actual_records) = try_join!( instance_recordsets( @@ -40,7 +40,7 @@ impl TryFrom<&AutoScalingGroup> for AutoScalingGroupConfig { .ok_or(anyhow!("Autoscaling group returned from AWS with no name"))? .to_owned(); - let instances = autoscaling_group.instances().unwrap_or(&[]); + let instances = autoscaling_group.instances(); let live_instance_ids = Self::live_instance_ids(instances); @@ -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)) } } diff --git a/src/route53.rs b/src/route53.rs index b9d4c34..3c34e9c 100644 --- a/src/route53.rs +++ b/src/route53.rs @@ -31,13 +31,9 @@ where .send() .await?; - let zones = zones_resp.hosted_zones().unwrap_or(&[]); + let zones = zones_resp.hosted_zones(); for candidate_zone in zones.iter() { - let zone_name = match candidate_zone.name() { - None => continue, - Some(name) => name, - }; - let zone_name = Name::from_str(zone_name)?; + let zone_name = Name::from_str(candidate_zone.name())?; let match_position = names.iter().position(|name| *name == zone_name); match (depth, match_position) { (None, Some(matched_depth)) => { @@ -89,21 +85,16 @@ where .send() .await?; - let recordsets = records_resp.resource_record_sets().unwrap_or(&[]); + let recordsets = records_resp.resource_record_sets(); for recordset in recordsets { - let recordset_name = recordset.name().ok_or(anyhow!( - "Record set with no name found in zone: {}", - zone_id - ))?; + let recordset_name = recordset.name(); let recordset_name = Name::from_str(recordset_name)?; if &recordset_name != dns_name { break; } - if let Some(rr_type) = recordset.r#type() { - if [RrType::A, RrType::Aaaa].contains(rr_type) { - suffix_records.insert(recordset.clone().into()); - } + if [RrType::A, RrType::Aaaa].contains(recordset.r#type()) { + suffix_records.insert(recordset.clone().into()); } } |
