2019-04-09 12:43:30 +00:00
|
|
|
use failure::*;
|
|
|
|
|
|
|
|
use crate::tools;
|
2019-02-17 09:16:33 +00:00
|
|
|
use crate::api_schema::*;
|
2019-02-17 08:59:20 +00:00
|
|
|
use crate::api_schema::router::*;
|
2019-01-23 12:05:32 +00:00
|
|
|
use serde_json::{json};
|
2019-04-09 12:43:30 +00:00
|
|
|
use lazy_static::lazy_static;
|
|
|
|
use std::sync::Arc;
|
2019-01-23 12:05:32 +00:00
|
|
|
|
2019-04-07 10:18:58 +00:00
|
|
|
mod tasks;
|
2019-01-23 12:05:32 +00:00
|
|
|
mod time;
|
|
|
|
mod network;
|
|
|
|
mod dns;
|
2019-01-25 16:17:30 +00:00
|
|
|
mod syslog;
|
2019-01-26 16:54:18 +00:00
|
|
|
mod services;
|
2019-01-23 12:05:32 +00:00
|
|
|
|
2019-04-09 12:43:30 +00:00
|
|
|
lazy_static!{
|
|
|
|
|
|
|
|
pub static ref NODE_SCHEMA: Arc<Schema> = Arc::new(
|
|
|
|
StringSchema::new("Node name (or 'localhost')")
|
|
|
|
.format(
|
|
|
|
Arc::new(ApiStringFormat::VerifyFn(|node| {
|
|
|
|
if node == "localhost" || node == tools::nodename() {
|
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
Err(format_err!("no such node '{}'", node))
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
)
|
|
|
|
.into()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-01-23 12:05:32 +00:00
|
|
|
pub fn router() -> Router {
|
|
|
|
|
|
|
|
let route = Router::new()
|
|
|
|
.get(ApiMethod::new(
|
2019-01-26 13:50:37 +00:00
|
|
|
|_,_,_| Ok(json!([
|
2019-01-27 11:40:31 +00:00
|
|
|
{"subdir": "dns"},
|
2019-01-23 12:05:32 +00:00
|
|
|
{"subdir": "network"},
|
2019-01-27 11:40:31 +00:00
|
|
|
{"subdir": "services"},
|
2019-01-25 16:17:30 +00:00
|
|
|
{"subdir": "syslog"},
|
|
|
|
{"subdir": "time"},
|
2019-01-23 12:05:32 +00:00
|
|
|
])),
|
|
|
|
ObjectSchema::new("Directory index.")))
|
|
|
|
.subdir("dns", dns::router())
|
|
|
|
.subdir("network", network::router())
|
2019-01-26 16:54:18 +00:00
|
|
|
.subdir("services", services::router())
|
2019-01-25 16:17:30 +00:00
|
|
|
.subdir("syslog", syslog::router())
|
2019-04-07 10:18:58 +00:00
|
|
|
.subdir("tasks", tasks::router())
|
2019-01-23 12:05:32 +00:00
|
|
|
.subdir("time", time::router());
|
|
|
|
|
|
|
|
route
|
|
|
|
}
|