summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-07-23 19:10:13 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-07-23 19:31:13 -0400
commit5429d2ab901380a92535e31c8cce6646e9b11c4f (patch)
tree760f274979c64185e6bc3710cc85030eb991cb0d /src/bin
parentbd0ab7e0b9ed4584e2973f96c25799aada2b52e9 (diff)
Move CLI glue inside of the lib crate.
This allows me to stop exporting symbols that were only exported for the purposes of making the CLI work. This commit makes the minimum version for the next release 0.2.0, as it retires multiple symbols that are part of the lib crate's API in v0.1.x.
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/aws-autoscaling-dns.rs9
-rw-r--r--src/bin/aws-autoscaling-dns/main.rs68
2 files changed, 9 insertions, 68 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/bin/aws-autoscaling-dns/main.rs
deleted file mode 100644
index 8da99b2..0000000
--- a/src/bin/aws-autoscaling-dns/main.rs
+++ /dev/null
@@ -1,68 +0,0 @@
-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;
-
-/// Synchronize a DNS entry with an autoscaling group's running instances.
-///
-/// The given DNS name's A and AAAA records in Route53 will be rewritten to exactly
-/// match the list of pending and in-service EC2 instances in the specified
-/// autoscaling group. Records of other types (including CNAMEs) will not be
-/// modified, so this can be used alongside DNS ACME verification, SPF, and other
-/// DNS applications.
-#[derive(Parser, Debug)]
-struct Args {
- /// The name of the autoscaling group to synchronize.
- #[arg(long)]
- autoscaling_group: String,
-
- /// The DNS domain name to synchronize. The most specific Route53 zone that
- /// contains this name will be modified.
- #[arg(long)]
- dns_name: Name,
-
- /// The TTL (in seconds) for newly-created records.
- #[arg(long, default_value_t = 60)]
- dns_ttl: i64,
-
- /// Print the affected zone ID and pending changes, without applying them (default).
- #[arg(long, conflicts_with = "apply")]
- dry_run: bool,
-
- /// Apply the changes to Route53.
- #[arg(long)]
- apply: bool,
-}
-
-#[tokio::main]
-async fn main() -> Result<()> {
- let args = Args::parse();
- let name = args.autoscaling_group;
-
- let aws_context = AwsContext::from_env().await;
-
- let apply_mode = if args.dry_run {
- ApplyMode::DryRun
- } else if args.apply {
- ApplyMode::Apply
- } else {
- ApplyMode::DryRun
- };
-
- 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(())
-}