bin/pbs-datastore.rs: start implementing cli commands

This commit is contained in:
Dietmar Maurer
2018-12-09 11:59:32 +01:00
parent 5b34c2607d
commit ea0b8b6ec0
4 changed files with 109 additions and 8 deletions

View File

@ -5,7 +5,7 @@ use crate::api::schema::*;
use crate::api::router::*;
use serde_json::{json};
mod datastore;
pub mod datastore;
pub fn router() -> Router {

View File

@ -7,20 +7,40 @@ use serde_json::{json, Value};
use crate::config::datastore;
fn datastore_list(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
println!("This is a test {}", param);
pub fn get() -> ApiMethod {
ApiMethod::new(
get_datastore_list,
ObjectSchema::new("Directory index."))
}
fn get_datastore_list(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
let config = datastore::config()?;
Ok(config.convert_to_array("id"))
Ok(config.convert_to_array("name"))
}
pub fn post() -> ApiMethod {
ApiMethod::new(
create_datastore,
ObjectSchema::new("Create new datastore.")
.required("name", StringSchema::new("Datastore name."))
.required("path", StringSchema::new("Directory path (must exist)."))
)
}
fn create_datastore(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
println!("This is a test {}", param);
Ok(json!({}))
}
pub fn router() -> Router {
let route = Router::new()
.get(ApiMethod::new(
datastore_list,
ObjectSchema::new("Directory index.")));
.get(get())
.post(post());
route
}