From 34d3ba52eb661a4977056c87a1237c0b3bf75b48 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sun, 9 Dec 2018 16:52:32 +0100 Subject: [PATCH] api3/config/datastore.rs: implement delete --- src/api3/config/datastore.rs | 31 +++++++++++++++++++++++++++++-- src/bin/pbs-datastore.rs | 6 ++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/api3/config/datastore.rs b/src/api3/config/datastore.rs index aa113a09..4589e76f 100644 --- a/src/api3/config/datastore.rs +++ b/src/api3/config/datastore.rs @@ -30,7 +30,6 @@ pub fn post() -> ApiMethod { } fn create_datastore(param: Value, _info: &ApiMethod) -> Result { - println!("This is a test {}", param); // fixme: locking ? @@ -53,11 +52,39 @@ fn create_datastore(param: Value, _info: &ApiMethod) -> Result { Ok(Value::Null) } +pub fn delete() -> ApiMethod { + ApiMethod::new( + delete_datastore, + ObjectSchema::new("Remove a datastore configuration.") + .required("name", StringSchema::new("Datastore name."))) +} + +fn delete_datastore(param: Value, _info: &ApiMethod) -> Result { + println!("This is a test {}", param); + + // fixme: locking ? + // fixme: check digest ? + + let mut config = datastore::config()?; + + let name = param["name"].as_str().unwrap(); + + match config.sections.get(name) { + Some(_) => { config.sections.remove(name); }, + None => bail!("datastore '{}' does not exist.", name), + } + + datastore::save_config(&config)?; + + Ok(Value::Null) +} + pub fn router() -> Router { let route = Router::new() .get(get()) - .post(post()); + .post(post()) + .delete(delete()); route diff --git a/src/bin/pbs-datastore.rs b/src/bin/pbs-datastore.rs index 2b140aca..3f81b61e 100644 --- a/src/bin/pbs-datastore.rs +++ b/src/bin/pbs-datastore.rs @@ -72,6 +72,12 @@ fn main() { fixed_param: vec![], }); + cmd_def.insert("remove".to_owned(), CliCommand { + info: api3::config::datastore::delete(), + arg_param: vec!["name"], + fixed_param: vec![], + }); + if let Err(err) = run_cli_command(&cmd_def) { eprintln!("Error: {}", err); print_cli_usage();