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"
description = "REST API Wrapper for Mikrotik API"
license = "MIT"
repository = "https://github.com/ishanjain28/mikrotik"
[dev-dependencies]
tokio-test = "0.4.2"

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,7 @@
mod client;
pub mod interface;
pub mod ip;
mod serde_helpers;
pub mod system;
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;
pub use health::*;
pub use types::*;
const BASE: &str = "rest/system";