Expose types, Correct malformed responses from mikrotik. added repository url

This commit is contained in:
Ishan Jain 2022-04-28 17:04:43 +05:30
parent 77abd9ece8
commit e6711968cc
8 changed files with 37 additions and 9 deletions

View File

@ -4,6 +4,7 @@ version = "0.0.6"
edition = "2021" edition = "2021"
description = "REST API Wrapper for Mikrotik API" description = "REST API Wrapper for Mikrotik API"
license = "MIT" license = "MIT"
repository = "https://github.com/ishanjain28/mikrotik"
[dev-dependencies] [dev-dependencies]
tokio-test = "0.4.2" tokio-test = "0.4.2"

View File

@ -2,5 +2,6 @@ mod interface;
mod types; mod types;
pub use interface::*; pub use interface::*;
pub use types::*;
const BASE: &str = "rest/interface"; const BASE: &str = "rest/interface";

View File

@ -7,7 +7,7 @@ pub struct Interface {
#[serde(rename = ".id")] #[serde(rename = ".id")]
pub id: String, pub id: String,
#[serde(rename = "actual-mtu")] #[serde(rename = "actual-mtu")]
pub actual_mtu: String, pub actual_mtu: Option<String>,
pub comment: Option<String>, pub comment: Option<String>,
#[serde(rename = "default-name")] #[serde(rename = "default-name")]
pub default_name: Option<String>, pub default_name: Option<String>,
@ -29,7 +29,7 @@ pub struct Interface {
pub mac_address: Option<String>, pub mac_address: Option<String>,
#[serde(rename = "max-l2mtu")] #[serde(rename = "max-l2mtu")]
pub max_l2mtu: Option<String>, pub max_l2mtu: Option<String>,
pub mtu: String, pub mtu: Option<String>,
pub name: String, pub name: String,
pub running: String, pub running: String,
#[serde(rename = "rx-byte")] #[serde(rename = "rx-byte")]

View File

@ -1,4 +1,6 @@
pub mod dhcp_server; pub mod dhcp_server;
mod types; mod types;
pub use types::*;
const BASE: &str = "rest/ip"; const BASE: &str = "rest/ip";

View File

@ -1,3 +1,4 @@
use crate::serde_helpers::deserialize_bool;
use serde_derive::Deserialize; use serde_derive::Deserialize;
use serde_derive::Serialize; use serde_derive::Serialize;
@ -9,10 +10,13 @@ pub struct DhcpServer {
#[serde(rename = "address-pool")] #[serde(rename = "address-pool")]
pub address_pool: String, pub address_pool: String,
pub authoritative: String, pub authoritative: String,
pub disabled: String, #[serde(deserialize_with = "deserialize_bool")]
pub dynamic: String, pub disabled: bool,
#[serde(deserialize_with = "deserialize_bool")]
pub dynamic: bool,
pub interface: String, pub interface: String,
pub invalid: String, #[serde(deserialize_with = "deserialize_bool")]
pub invalid: bool,
#[serde(rename = "lease-script")] #[serde(rename = "lease-script")]
pub lease_script: String, pub lease_script: String,
#[serde(rename = "lease-time")] #[serde(rename = "lease-time")]
@ -30,12 +34,14 @@ pub struct Lease {
pub address: String, pub address: String,
#[serde(rename = "address-lists")] #[serde(rename = "address-lists")]
pub address_lists: String, pub address_lists: String,
pub blocked: String, #[serde(deserialize_with = "deserialize_bool")]
pub blocked: bool,
#[serde(rename = "client-id")] #[serde(rename = "client-id")]
pub client_id: Option<String>, pub client_id: Option<String>,
#[serde(rename = "dhcp-option")] #[serde(rename = "dhcp-option")]
pub dhcp_option: String, pub dhcp_option: String,
pub disabled: String, #[serde(deserialize_with = "deserialize_bool")]
pub disabled: bool,
pub dynamic: String, pub dynamic: String,
#[serde(rename = "host-name")] #[serde(rename = "host-name")]
pub host_name: Option<String>, pub host_name: Option<String>,
@ -43,7 +49,8 @@ pub struct Lease {
pub last_seen: String, pub last_seen: String,
#[serde(rename = "mac-address")] #[serde(rename = "mac-address")]
pub mac_address: String, pub mac_address: String,
pub radius: String, #[serde(deserialize_with = "deserialize_bool")]
pub radius: bool,
pub server: String, pub server: String,
pub status: String, pub status: String,
#[serde(rename = "active-address")] #[serde(rename = "active-address")]
@ -72,7 +79,8 @@ pub struct Network {
#[serde(rename = "dns-server")] #[serde(rename = "dns-server")]
pub dns_server: String, pub dns_server: String,
pub domain: Option<String>, pub domain: Option<String>,
pub dynamic: String, #[serde(deserialize_with = "deserialize_bool")]
pub dynamic: bool,
pub gateway: String, pub gateway: String,
pub netmask: String, pub netmask: String,
#[serde(rename = "ntp-server")] #[serde(rename = "ntp-server")]

View File

@ -1,6 +1,7 @@
mod client; mod client;
pub mod interface; pub mod interface;
pub mod ip; pub mod ip;
mod serde_helpers;
pub mod system; pub mod system;
pub use client::*; pub use client::*;

14
src/serde_helpers/mod.rs Normal file
View File

@ -0,0 +1,14 @@
use serde::{de::Error, Deserialize, Deserializer};
pub fn deserialize_bool<'de, D>(deserializer: D) -> Result<bool, D::Error>
where
D: Deserializer<'de>,
{
let s: &str = Deserialize::deserialize(deserializer)?;
match s {
"true" => Ok(true),
"false" => Ok(false),
_ => Err(Error::unknown_variant(s, &["true", "false"])),
}
}

View File

@ -2,5 +2,6 @@ mod health;
mod types; mod types;
pub use health::*; pub use health::*;
pub use types::*;
const BASE: &str = "rest/system"; const BASE: &str = "rest/system";