summaryrefslogtreecommitdiff
path: root/src/route53.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/route53.rs')
-rw-r--r--src/route53.rs51
1 files changed, 47 insertions, 4 deletions
diff --git a/src/route53.rs b/src/route53.rs
index e4379af..e63ce4c 100644
--- a/src/route53.rs
+++ b/src/route53.rs
@@ -3,21 +3,23 @@ use std::str::FromStr;
use anyhow::{anyhow, Result};
use aws_sdk_route53 as route53;
-use aws_sdk_route53::types::{HostedZone, ResourceRecordSet, RrType};
+use aws_sdk_route53::types::{HostedZone, ResourceRecord, ResourceRecordSet, RrType};
+// 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::suffixes;
+use crate::dns;
use crate::hashable::Hashable;
pub trait Route53 {
fn route53(&self) -> &route53::Client;
}
-pub async fn zone_for_domain<C>(aws_context: &C, name: &Name) -> Result<HostedZone>
+pub async fn zone_for_name<C>(aws_context: &C, name: &Name) -> Result<HostedZone>
where
C: Route53,
{
- let names = suffixes(name.clone());
+ let names = dns::suffixes(name.clone());
let mut zone = None;
let mut depth = None;
@@ -98,3 +100,44 @@ where
Ok(suffix_records)
}
+
+pub struct Target {
+ name: Name,
+ ttl: i64,
+}
+
+impl Target {
+ pub fn new(name: &Name, ttl: i64) -> Result<Self> {
+ let name = dns::absolute(name.to_owned())?;
+ Ok(Self { name, ttl })
+ }
+
+ pub fn name(&self) -> &Name {
+ &self.name
+ }
+
+ pub fn host_proposal(
+ &self,
+ rr_type: RrType,
+ addresses: HashSet<impl Into<String>>,
+ ) -> Result<Option<ResourceRecordSet>> {
+ if addresses.is_empty() {
+ Ok(None)
+ } else {
+ let records = addresses
+ .into_iter()
+ .map(|address| address.into())
+ .map(|address| ResourceRecord::builder().value(address).build())
+ .try_collect()?;
+
+ let record_set = ResourceRecordSet::builder()
+ .name(self.name().to_ascii())
+ .r#type(rr_type)
+ .ttl(self.ttl)
+ .set_resource_records(Some(records))
+ .build()?;
+
+ Ok(Some(record_set))
+ }
+ }
+}