You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
3.9 KiB

use crate::{
responses::{
VMListResponse,
BillingCreditResponse,
LNImageListResponse,
VolumeListResponse,
FloatingIpListResponse,
},
types::{
LNError,
LNErrorResponse,
LunaNodeRequest,
LunaNodeResponse,
ApiKeys,
},
};
use lunanode_macros::lunanode_request;
use parse_display_derive::Display;
use ureq::post;
use serde::{
Serialize,
Deserialize,
de::DeserializeOwned,
};
use hmac::{Hmac, Mac};
use sha2::Sha512;
#[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 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::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 vm help`
Vm(VmSubArgs),
#[clap(subcommand)]
/// See `lunanode billing help`
Billing(BillingSubArgs),
#[clap(subcommand)]
/// See `lunanode volume help`
Volume(VolumeSubArgs),
}
impl Args {
pub fn make_request(&self) -> Result<(), LNError> {
match self {
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);
},
}
Ok(())
}
}
#[lunanode_request(response="LNImageListResponse", endpoint="image/list/")]
#[derive(Serialize, Deserialize, Debug, Hash, PartialEq, Eq, clap::Args)]
/// ImageListRequest is used to create a new request for the /image/list endpoint.
pub struct ImageListRequest {}
#[lunanode_request(response="BillingCreditResponse", endpoint="billing/credit/")]
#[derive(Serialize, Deserialize, Debug, Hash, PartialEq, Eq, clap::Args, Display)]
/// BillingCreditRequest handles the /billing/credits/ endpoint. It will produce a BillingCreditResponse.
pub struct BillingCreditRequest {}
#[lunanode_request(response="VMListResponse", endpoint="vm/list/")]
#[derive(Serialize, Deserialize, Debug, Hash, PartialEq, Eq, clap::Args, Display)]
/// VMListRequest is used to create a new request for the /vm/list endpoint.
pub struct VMListRequest {}
#[lunanode_request(response="VolumeListResponse", endpoint="volume/list/")]
#[derive(Serialize, Deserialize, Debug, Hash, PartialEq, Eq, clap::Args, Display)]
/// VolumeListRequest is used to create a new request for the /volume/list endpoint.
pub struct VolumeListRequest {}
#[lunanode_request(response="FloatingIpListResponse", endpoint="floating/list/")]
#[derive(Serialize, Deserialize, Debug, Hash, PartialEq, Eq, clap::Args, Display)]
/// IpListRequest is used to create a new request for the /ip/list endpoint.
pub struct FloatingIpListRequest {}