diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/aws-autoscaling-dns.rs | 9 | ||||
| -rw-r--r-- | src/cli.rs (renamed from src/bin/aws-autoscaling-dns/main.rs) | 56 | ||||
| -rw-r--r-- | src/lib.rs | 9 |
3 files changed, 43 insertions, 31 deletions
diff --git a/src/bin/aws-autoscaling-dns.rs b/src/bin/aws-autoscaling-dns.rs new file mode 100644 index 0000000..6999b6b --- /dev/null +++ b/src/bin/aws-autoscaling-dns.rs @@ -0,0 +1,9 @@ +use clap::Parser; + +use aws_autoscaling_dns::cli; + +#[tokio::main] +async fn main() -> cli::Result { + let args = cli::Args::parse(); + args.run().await +} diff --git a/src/bin/aws-autoscaling-dns/main.rs b/src/cli.rs index 8da99b2..75bb5ef 100644 --- a/src/bin/aws-autoscaling-dns/main.rs +++ b/src/cli.rs @@ -3,10 +3,9 @@ use std::fmt::Debug; use clap::Parser; use trust_dns_proto::rr::Name; -use aws_autoscaling_dns::apply::ApplyMode; -use aws_autoscaling_dns::aws_context::AwsContext; -use aws_autoscaling_dns::converge::named_asg_changes; -use aws_autoscaling_dns::result::Result; +use crate::apply::ApplyMode; +use crate::aws_context::AwsContext; +use crate::converge::named_asg_changes; /// Synchronize a DNS entry with an autoscaling group's running instances. /// @@ -16,7 +15,7 @@ use aws_autoscaling_dns::result::Result; /// modified, so this can be used alongside DNS ACME verification, SPF, and other /// DNS applications. #[derive(Parser, Debug)] -struct Args { +pub struct Args { /// The name of the autoscaling group to synchronize. #[arg(long)] autoscaling_group: String, @@ -39,30 +38,33 @@ struct Args { apply: bool, } -#[tokio::main] -async fn main() -> Result<()> { - let args = Args::parse(); - let name = args.autoscaling_group; +pub type Result = crate::result::Result<()>; - let aws_context = AwsContext::from_env().await; +impl Args { + pub async fn run(self) -> Result { + let args = Args::parse(); + let name = args.autoscaling_group; - let apply_mode = if args.dry_run { - ApplyMode::DryRun - } else if args.apply { - ApplyMode::Apply - } else { - ApplyMode::DryRun - }; + let aws_context = AwsContext::from_env().await; - let changes = named_asg_changes(&aws_context, &name, &args.dns_name, args.dns_ttl).await?; - apply_mode - .apply( - &aws_context, - &changes.zone_id, - changes.remove, - changes.insert, - ) - .await?; + let apply_mode = if args.dry_run { + ApplyMode::DryRun + } else if args.apply { + ApplyMode::Apply + } else { + ApplyMode::DryRun + }; - Ok(()) + let changes = named_asg_changes(&aws_context, &name, &args.dns_name, args.dns_ttl).await?; + apply_mode + .apply( + &aws_context, + &changes.zone_id, + changes.remove, + changes.insert, + ) + .await?; + + Ok(()) + } } @@ -1,10 +1,11 @@ -pub mod apply; +mod apply; mod autoscaling; -pub mod aws_context; -pub mod converge; +mod aws_context; +pub mod cli; +mod converge; mod dns; mod ec2; mod hashable; -pub mod result; +mod result; mod route53; mod single; |
