api2/node/syslog.rs: add syslog api schema

This commit is contained in:
Dietmar Maurer 2019-01-25 17:17:30 +01:00
parent 68cacc0066
commit 4f9a726833
3 changed files with 75 additions and 2 deletions

View File

@ -5,6 +5,7 @@ use serde_json::{json};
mod time;
mod network;
mod dns;
mod syslog;
pub fn router() -> Router {
@ -12,11 +13,13 @@ pub fn router() -> Router {
.get(ApiMethod::new(
|_,_| Ok(json!([
{"subdir": "network"},
{"subdir": "time"},
{"subdir": "syslog"},
{"subdir": "time"},
])),
ObjectSchema::new("Directory index.")))
.subdir("dns", dns::router())
.subdir("network", network::router())
.subdir("syslog", syslog::router())
.subdir("time", time::router());
route

64
src/api2/node/syslog.rs Normal file
View File

@ -0,0 +1,64 @@
use failure::*;
use crate::tools;
use crate::api::schema::*;
use crate::api::router::*;
use serde_json::{json, Value};
use std::sync::Arc;
use lazy_static::lazy_static;
use crate::tools::common_regex;
fn get_syslog(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
let result = json!({});
Ok(result)
}
lazy_static! {
pub static ref SYSTEMD_DATETIME_FORMAT: Arc<ApiStringFormat> =
ApiStringFormat::Pattern(&common_regex::SYSTEMD_DATETIME_REGEX).into();
}
pub fn router() -> Router {
let route = Router::new()
.get(
ApiMethod::new(
get_syslog,
ObjectSchema::new("Read server time and time zone settings.")
.optional(
"start",
IntegerSchema::new("Start line number.")
.minimum(0)
)
.optional(
"limit",
IntegerSchema::new("Max. number of lines.")
.minimum(0)
)
.optional(
"since",
StringSchema::new("Display all log since this date-time string.")
.format(SYSTEMD_DATETIME_FORMAT.clone())
)
.optional(
"until",
StringSchema::new("Display all log until this date-time string.")
.format(SYSTEMD_DATETIME_FORMAT.clone())
)
.optional(
"service",
StringSchema::new("Service ID.")
.max_length(128)
)
).returns(
ObjectSchema::new("Returns a list of syslog entries.")
.required("n", IntegerSchema::new("Line number."))
.required("t", StringSchema::new("Line text."))
)
);
route
}

View File

@ -35,5 +35,11 @@ macro_rules! IPRE { () => (concat!(r"(?:", IPV4RE!(), "|", IPV6RE!(), ")")) }
lazy_static! {
pub static ref IP_REGEX: Regex = Regex::new(IPRE!()).unwrap();
pub static ref SHA256_HEX_REGEX: Regex = Regex::new("^[a-f0-9]{64}$").unwrap();
pub static ref SHA256_HEX_REGEX: Regex =
Regex::new(r"^[a-f0-9]{64}$")
.unwrap();
pub static ref SYSTEMD_DATETIME_REGEX: Regex =
Regex::new(r"^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}(:\d{2})?)?$")
.unwrap();
}