From 97182beef37ac020f4569f8f60924ad5e175a01a Mon Sep 17 00:00:00 2001 From: Tait Hoyem Date: Tue, 27 Sep 2022 08:49:52 -0600 Subject: [PATCH] Add contact list endpoint --- src/requests.rs | 37 ++++++++++++++++++++++++++ src/responses.rs | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) diff --git a/src/requests.rs b/src/requests.rs index 5e119b0..0387295 100644 --- a/src/requests.rs +++ b/src/requests.rs @@ -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 {} diff --git a/src/responses.rs b/src/responses.rs index 5355164..451c33f 100644 --- a/src/responses.rs +++ b/src/responses.rs @@ -514,3 +514,72 @@ pub struct EmailDomainListResponse { #[serde(flatten)] domains: std::collections::HashMap, } + +#[lunanode_response] +pub struct MonitorCheckListResponse { + /// This is not done yet. A Check type will be required. TODO + checks: Vec, +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(untagged)] +pub enum ParamType { + Single(String), + Options(std::collections::HashMap), +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct Param { + #[serde(with="external")] + required: bool, + r#type: ParamType, + name: String, + placeholder: Option, +} + +#[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 +} + +#[lunanode_response] +pub struct MonitorCheckTypesResponse { + types: std::collections::HashMap, +} + +#[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), + /// 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), +} + +#[lunanode_response] +pub struct MonitorContactListResponse { + /// A list of contacts in your LunaNode account. This should be deserialized as Option>, but I haven't gotten around to serializing this in that way. TODO. + contacts: Contacts, +}