Add contact list endpoint

master
Tait Hoyem 2 years ago
parent 56167d5d10
commit 97182beef3

@ -14,6 +14,9 @@ use crate::{
RegionListResponse,
EmailUsageResponse,
EmailDomainListResponse,
MonitorCheckListResponse,
MonitorCheckTypesResponse,
MonitorContactListResponse,
},
types::{
LNError,
@ -114,6 +117,25 @@ pub enum RegionSubArgs {
List(RegionListRequest),
}
#[derive(Serialize, Deserialize, Debug, clap::Subcommand)]
pub enum MonitorCheckSubArgs {
List(MonitorCheckListRequest),
Types(MonitorCheckTypesRequest),
}
#[derive(Serialize, Deserialize, Debug, clap::Subcommand)]
pub enum MonitorContactSubArgs {
List(MonitorContactListRequest),
}
#[derive(Serialize, Deserialize, Debug, clap::Subcommand)]
pub enum MonitorSubArgs {
#[clap(subcommand)]
Check(MonitorCheckSubArgs),
#[clap(subcommand)]
Contact(MonitorContactSubArgs),
}
#[derive(Serialize, Deserialize, Debug, clap::Parser)]
#[serde(untagged)]
pub enum Args {
@ -156,6 +178,9 @@ pub enum Args {
#[clap(subcommand)]
/// See `lunanode email help`
Email(EmailSubArgs),
#[clap(subcommand)]
/// See `lunanode monitor help`
Monitor(MonitorSubArgs),
}
/// Specifies an internal function which can only be called on LunaNodeRequests whoes response type implements Debug. This could be set in the structure itself, and probably should be.
@ -170,6 +195,9 @@ where
impl Args {
pub fn make_request(&self) -> Result<(), LNError> {
match self {
Self::Monitor(MonitorSubArgs::Contact(MonitorContactSubArgs::List(contact_list))) => print_req(contact_list)?,
Self::Monitor(MonitorSubArgs::Check(MonitorCheckSubArgs::Types(monitor_check_types))) => print_req(monitor_check_types)?,
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::Network(NetworkSubArgs::List(net_list)) => print_req(net_list)?,
@ -241,3 +269,12 @@ pub struct EmailUsageRequest {}
#[lunanode_request(response="EmailDomainListResponse", endpoint="email/domain-list/")]
pub struct EmailDomainListRequest {}
#[lunanode_request(response="MonitorCheckListResponse", endpoint="monitor/check-list/")]
pub struct MonitorCheckListRequest {}
#[lunanode_request(response="MonitorCheckTypesResponse", endpoint="monitor/check-types/")]
pub struct MonitorCheckTypesRequest {}
#[lunanode_request(response="MonitorContactListResponse", endpoint="monitor/contact-list/")]
pub struct MonitorContactListRequest {}

@ -514,3 +514,72 @@ pub struct EmailDomainListResponse {
#[serde(flatten)]
domains: std::collections::HashMap<String,EmailDomainInfo>,
}
#[lunanode_response]
pub struct MonitorCheckListResponse {
/// This is not done yet. A Check type will be required. TODO
checks: Vec<String>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(untagged)]
pub enum ParamType {
Single(String),
Options(std::collections::HashMap<String, String>),
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Param {
#[serde(with="external")]
required: bool,
r#type: ParamType,
name: String,
placeholder: Option<String>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct MonitorTypes {
/// The name of the monitor type.
name: String,
/// The short name of the monitor type.
short_name: String,
params: std::collections::HashMap<String, Param>
}
#[lunanode_response]
pub struct MonitorCheckTypesResponse {
types: std::collections::HashMap<String, MonitorTypes>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all="lowercase")]
pub enum ContactType {
Email,
Sms,
Voice,
Http,
}
#[serde_as]
#[derive(Serialize, Deserialize, Debug)]
pub struct Contact {
#[serde_as(as="DisplayFromStr")]
id: i32,
r#type: ContactType,
data: String,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(untagged)]
pub enum Contacts {
/// Need an empty vec of some kind to hold the blank value, which appears as [].
Empty(Vec<String>),
/// Note that this HashMap should be indexed by i32, not String. This is a limitation of serde as far as I can tell.
Populated(std::collections::HashMap<String, Contact>),
}
#[lunanode_response]
pub struct MonitorContactListResponse {
/// A list of contacts in your LunaNode account. This should be deserialized as Option<HashMap<String, Contact>>, but I haven't gotten around to serializing this in that way. TODO.
contacts: Contacts,
}

Loading…
Cancel
Save