api3/config/datastore.rs: impl create

This commit is contained in:
Dietmar Maurer
2018-12-09 12:51:31 +01:00
parent ea0b8b6ec0
commit 652c11900d
2 changed files with 44 additions and 2 deletions

View File

@ -32,7 +32,25 @@ pub fn post() -> ApiMethod {
fn create_datastore(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
println!("This is a test {}", param);
Ok(json!({}))
// fixme: locking ?
let mut config = datastore::config()?;
let name = param["name"].as_str().unwrap();
if let Some(_) = config.sections.get(name) {
bail!("datastore '{}' already exists.", name);
}
let datastore = json!({
"path": param["path"]
});
config.set_data(name, "datastore", datastore);
datastore::save_config(&config)?;
Ok(Value::Null)
}
pub fn router() -> Router {