From fdac840e69ec13bc8e13adc3fe2c1e2cd1c7e027 Mon Sep 17 00:00:00 2001 From: Tait Hoyem Date: Sun, 4 Dec 2022 14:59:24 -0700 Subject: [PATCH] Add more DNS record managment --- README.md | 15 ++++++++------- src/requests.rs | 18 ++++++++++++++++++ src/responses.rs | 5 +++++ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1a3065f..97af45c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # `lunanode` This is an API to work with the LunaNode's OpenStack-compatible [citation needed] API. -This crate currently covers only the most basic functionality from the Lunanode API. Currently 33/98 (34%) API calls. +This crate currently covers only the most basic functionality from the Lunanode API. Currently 36/98 (37%) API calls. If you'd like to contribute additional functionality, please feel free to make an MR. * VM [8/21] @@ -110,15 +110,15 @@ If you'd like to contribute additional functionality, please feel free to make a * List [ ] * Add [ ] * Remove [ ] -* DNS [6/10] - * Zone [2/3] +* DNS [9/10] + * Zone [3/3] * List [X] * Add [X] - * Remove [ ] - * Record [1/3] + * Remove [X] + * Record [3/3] * List [X] - * Add [ ] - * Remove [ ] + * Add [X] + * Remove [X] * Dyn [3/4] * List [X] * Add [X] @@ -134,6 +134,7 @@ If you'd like to contribute additional functionality, please feel free to make a ## API Keys Add the `LUNANODE_API_KEY`, `LUNANODE_KEY_ID` and `LUNANODE_API_PARTIALKEY` (the first 64 chars of `LUNANODE_API_KEY`) to your environment variables. +Without these variables set, the tool will not run. You can also specify the keys manually through command-line arguments. ## Usage diff --git a/src/requests.rs b/src/requests.rs index c165030..4f3152b 100644 --- a/src/requests.rs +++ b/src/requests.rs @@ -14,6 +14,7 @@ use crate::{ RecordType, RecordListResponse, RecordAddResponse, + RecordRemoveResponse, DynListResponse, DynAddResponse, DynRemoveResponse, @@ -45,6 +46,7 @@ use serde::{ Serialize, Deserialize, }; +use serde_with::skip_serializing_none; #[derive(Serialize, Deserialize, Debug, clap::Subcommand)] /// All possible `ssh-key` subcommands. @@ -129,6 +131,10 @@ pub enum ImageSubArgs { pub enum RecordSubArgs { /// List all records in a domain. List(RecordListRequest), + /// Add a new DNS record to a domain. + Add(RecordAddRequest), + /// Remove a DNS record for a domain. + Remove(RecordRemoveRequest), } #[derive(Serialize, Deserialize, Debug, clap::Subcommand)] @@ -286,6 +292,8 @@ impl Args { Self::Monitor(MonitorSubArgs::Check(MonitorCheckSubArgs::List(monitor_check_list))) => print_req(monitor_check_list)?, Self::SshKey(SshKeySubArgs::List(ssk_list)) => print_req(ssk_list)?, Self::Record(RecordSubArgs::List(rec_list)) => print_req(rec_list)?, + Self::Record(RecordSubArgs::Add(add_req)) => print_req(add_req)?, + Self::Record(RecordSubArgs::Remove(rem_req)) => print_req(rem_req)?, Self::Network(NetworkSubArgs::List(net_list)) => print_req(net_list)?, Self::Floating(FloatingSubArgs::List(ip_list)) => print_req(ip_list)?, Self::Vm(VmSubArgs::List(vm_list)) => print_req(vm_list)?, @@ -497,6 +505,7 @@ pub enum RecordPolicyType { Region, } +#[skip_serializing_none] #[lunanode_request(response="RecordAddResponse", endpoint="dns2/record-add/")] /// Add a new DNS record to your zone. pub struct RecordAddRequest { @@ -523,3 +532,12 @@ pub struct RecordAddRequest { /// If set, update the existing record with this ID instead of creating a new record. orig_record_id: Option, } + +#[lunanode_request(response="RecordRemoveResponse", endpoint="dns2/record-remove/")] +/// Remove a DNS record from a given zone. +pub struct RecordRemoveRequest { + /// The ID of the zone which the DNS record is contained in. This is usually an FQDN like example.com, but we just need the zone ID from Lunanode. See: [`ZoneListResponse`]. + zone_id: i32, + /// The ID of the DNS record to remove. See [`RecordListResponse`] + record_id: i32, +} diff --git a/src/responses.rs b/src/responses.rs index e9eef49..33234d7 100644 --- a/src/responses.rs +++ b/src/responses.rs @@ -864,3 +864,8 @@ pub struct ZoneRemoveResponse {} /// The result of adding a new record. /// See also: [`crate::requests::RecordAddRequest`] pub struct RecordAddResponse {} + +#[lunanode_response] +/// The result of remove a DNS record. +/// See also: [`crate::requests::RecordRemoveRequest`] +pub struct RecordRemoveResponse {}