Add , subcommands

master
Tait Hoyem 2 years ago
parent 37cba73953
commit 393ae2a07c

@ -8,6 +8,8 @@ use crate::{
NetworkListResponse,
ZoneListResponse,
RecordListResponse,
DynListResponse,
SshKeyResponse,
},
types::{
LNError,
@ -26,6 +28,16 @@ use serde::{
use hmac::Hmac;
use sha2::Sha512;
#[derive(Serialize, Deserialize, Debug, clap::Subcommand)]
pub enum SshKeySubArgs {
List(SshKeyRequest),
}
#[derive(Serialize, Deserialize, Debug, clap::Subcommand)]
pub enum DynSubArgs {
List(DynListRequest),
}
#[derive(Serialize, Deserialize, Debug, clap::Subcommand)]
pub enum ZoneSubArgs {
List(ZoneListRequest),
@ -103,10 +115,20 @@ pub enum Args {
#[clap(subcommand)]
/// See `lunanode record help`
Record(RecordSubArgs),
#[clap(subcommand)]
/// See `lunanode dyn help`
Dyn(DynSubArgs),
#[clap(subcommand)]
/// See `lunanode sshkey help`
SshKey(SshKeySubArgs),
}
impl Args {
pub fn make_request(&self) -> Result<(), LNError> {
match self {
Self::SshKey(SshKeySubArgs::List(ssk_list)) => {
let list = ssk_list.make_request()?;
println!("{:#?}", list);
},
Self::Record(RecordSubArgs::List(rec_list)) => {
let list = rec_list.make_request()?;
println!("{:#?}", list);
@ -139,6 +161,10 @@ impl Args {
let list = zone_list.make_request()?;
println!("{:#?}", list);
},
Self::Dyn(DynSubArgs::List(dyn_list)) => {
let list = dyn_list.make_request()?;
println!("{:#?}", list);
},
}
Ok(())
}
@ -178,8 +204,9 @@ 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 {}
*/
#[lunanode_request(response="SshKeyResponse", endpoint="sshkey/list/")]
pub struct SshKeyRequest {}

@ -449,3 +449,35 @@ pub struct Record {
pub struct RecordListResponse {
records: std::collections::HashMap<i32, Record>,
}
#[serde_as]
#[derive(Serialize, Deserialize, Debug)]
pub struct DynRecord {
#[serde_as(as="DisplayFromStr")]
id: i32,
name: String,
ip: IPAddress,
}
#[lunanode_response]
pub struct DynListResponse {
dyns: std::collections::HashMap<i32, DynRecord>,
}
#[serde_as]
#[derive(Serialize, Deserialize, Debug)]
pub struct SshKey {
#[serde_as(as="DisplayFromStr")]
id: i32,
/// Name of key, as specified by the user.
name: String,
/// The value of the SSH key; this is not more strict, only because the value is meant to be literal and not a "structured" representation of an SSH key. In addition, this would take a lot of extra boilerplate.
value: String,
}
#[lunanode_response]
pub struct SshKeyResponse {
#[serde(flatten)]
/// List of keys stored in the LunaNode cloud. The String is just an index that I can't get to flatten :grumpy programmer noises:
keys: std::collections::HashMap<String, SshKey>,
}

Loading…
Cancel
Save