use crate::{ responses::{ VMListResponse, BillingCreditResponse, LNImageListResponse, VolumeListResponse, FloatingIpListResponse, NetworkListResponse, ZoneListResponse, RecordListResponse, }, types::{ LNError, LunaNodeRequest, ApiKeys, }, }; use lunanode_macros::lunanode_request; use parse_display_derive::Display; use ureq::post; use serde::{ Serialize, Deserialize, de::DeserializeOwned, }; use hmac::Hmac; use sha2::Sha512; #[derive(Serialize, Deserialize, Debug, clap::Subcommand)] pub enum ZoneSubArgs { List(ZoneListRequest), } #[derive(Serialize, Deserialize, Debug, clap::Subcommand)] #[serde(untagged)] pub enum FloatingSubArgs { /// List all images on my account. List(FloatingIpListRequest), } #[derive(Serialize, Deserialize, Debug, clap::Subcommand)] #[serde(untagged)] pub enum ImageSubArgs { /// List all images on my account. List(ImageListRequest), } #[derive(Serialize, Deserialize, Debug, clap::Subcommand)] #[serde(untagged)] pub enum RecordSubArgs { List(RecordListRequest), } #[derive(Serialize, Deserialize, Debug, clap::Subcommand)] #[serde(untagged)] pub enum VmSubArgs { /// List all VMs on my account. List(VMListRequest), } #[derive(Serialize, Deserialize, Debug, clap::Subcommand)] #[serde(untagged)] pub enum VolumeSubArgs { /// List all volumes I'm paying for. List(VolumeListRequest), } #[derive(Serialize, Deserialize, Debug, clap::Subcommand)] #[serde(untagged)] pub enum BillingSubArgs { /// How much money is left in my account. Credit(BillingCreditRequest), } #[derive(Serialize, Deserialize, Debug, clap::Subcommand)] #[serde(untagged)] pub enum NetworkSubArgs { /// Networks on your accounts List(NetworkListRequest), } #[derive(Serialize, Deserialize, Debug, clap::Parser)] #[serde(untagged)] pub enum Args { #[clap(subcommand)] /// See `lunanode image help` Image(ImageSubArgs), #[clap(subcommand)] /// See `lunanode ip help` Floating(FloatingSubArgs), #[clap(subcommand)] /// See `lunanode network help` Network(NetworkSubArgs), #[clap(subcommand)] /// See `lunanode vm help` Vm(VmSubArgs), #[clap(subcommand)] /// See `lunanode billing help` Billing(BillingSubArgs), #[clap(subcommand)] /// See `lunanode volume help` Volume(VolumeSubArgs), #[clap(subcommand)] /// See `lunanode zone help` Zone(ZoneSubArgs), #[clap(subcommand)] /// See `lunanode record help` Record(RecordSubArgs), } impl Args { pub fn make_request(&self) -> Result<(), LNError> { match self { Self::Record(RecordSubArgs::List(rec_list)) => { let list = rec_list.make_request()?; println!("{:#?}", list); }, Self::Network(NetworkSubArgs::List(net_list)) => { let list = net_list.make_request()?; println!("{:#?}", list); }, Self::Floating(FloatingSubArgs::List(ip_list)) => { let list = ip_list.make_request()?; println!("{:#?}", list); }, Self::Vm(VmSubArgs::List(vm_list)) => { let list = vm_list.make_request()?; println!("{:#?}", list); }, Self::Volume(VolumeSubArgs::List(vol_list)) => { let list = vol_list.make_request()?; println!("{:#?}", list); }, Self::Image(ImageSubArgs::List(image_list)) => { let list = image_list.make_request()?; println!("{:#?}", list); }, Self::Billing(BillingSubArgs::Credit(billing_credit)) => { let credit =billing_credit.make_request()?; println!("{:#?}", credit); }, Self::Zone(ZoneSubArgs::List(zone_list)) => { let list = zone_list.make_request()?; println!("{:#?}", list); }, } Ok(()) } } /// ImageListRequest is used to create a new request for the /image/list endpoint. #[lunanode_request(response="LNImageListResponse", endpoint="image/list/")] pub struct ImageListRequest {} /// BillingCreditRequest handles the /billing/credits/ endpoint. It will produce a BillingCreditResponse. #[lunanode_request(response="BillingCreditResponse", endpoint="billing/credit/")] pub struct BillingCreditRequest {} /// VMListRequest is used to create a new request for the /vm/list endpoint. #[lunanode_request(response="VMListResponse", endpoint="vm/list/")] pub struct VMListRequest {} /// VolumeListRequest is used to create a new request for the /volume/list endpoint. #[lunanode_request(response="VolumeListResponse", endpoint="volume/list/")] pub struct VolumeListRequest {} /// IpListRequest is used to create a new request for the /ip/list endpoint. #[lunanode_request(response="FloatingIpListResponse", endpoint="floating/list/")] pub struct FloatingIpListRequest {} /// NetworkListRequest is used to create a new request for the /network/list endpoint. #[lunanode_request(response="NetworkListResponse", endpoint="network/list/")] pub struct NetworkListRequest {} /// ZoneListRequest is used to generate a request for the dns2/zone-list/ endpoint. #[lunanode_request(response="ZoneListResponse", endpoint="dns2/zone-list/")] pub struct ZoneListRequest {} /// RecordListRequest is used to get information about a specific DNS zone (usually an entire domain, but could also be a subdomain). #[lunanode_request(response="RecordListResponse", endpoint="dns2/record-list/")] pub struct RecordListRequest { zone_id: i32 } /* /// DynListRequest is used to get information about the dynamic DNS records set for all lunanode zones. #[lunanode_request(response="DynListResponse", endpoint="dns/dyn-list/")] pub struct DynListRequest {} */