api: pass RpcEnvirnment to api handlers

This commit is contained in:
Dietmar Maurer
2019-01-26 14:50:37 +01:00
parent d96d82736d
commit 6049b71f41
18 changed files with 252 additions and 109 deletions

View File

@ -8,7 +8,7 @@ pub fn router() -> Router {
let route = Router::new()
.get(ApiMethod::new(
|_,_| Ok(json!([
|_,_,_| Ok(json!([
{"subdir": "datastore"}
])),
ObjectSchema::new("Directory index.")))

View File

@ -15,7 +15,11 @@ use crate::backup::datastore::*;
mod catar;
// this is just a test for mutability/mutex handling - will remove later
fn start_garbage_collection(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
fn start_garbage_collection(
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
) -> Result<Value, Error> {
let store = param["store"].as_str().unwrap();
@ -36,7 +40,11 @@ pub fn api_method_start_garbage_collection() -> ApiMethod {
)
}
fn garbage_collection_status(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
fn garbage_collection_status(
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
) -> Result<Value, Error> {
let store = param["store"].as_str().unwrap();
@ -54,7 +62,11 @@ pub fn api_method_garbage_collection_status() -> ApiMethod {
)
}
fn get_backup_list(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
fn get_backup_list(
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
) -> Result<Value, Error> {
let config = datastore::config()?;
@ -77,7 +89,11 @@ fn get_backup_list(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
Ok(result)
}
fn get_datastore_list(_param: Value, _info: &ApiMethod) -> Result<Value, Error> {
fn get_datastore_list(
_param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
) -> Result<Value, Error> {
let config = datastore::config()?;
@ -89,7 +105,7 @@ pub fn router() -> Router {
let datastore_info = Router::new()
.get(ApiMethod::new(
|_,_| Ok(json!([
|_,_,_| Ok(json!([
{"subdir": "backups" },
{"subdir": "catar" },
{"subdir": "status"},

View File

@ -11,7 +11,7 @@ pub fn router() -> Router {
let route = Router::new()
.get(ApiMethod::new(
|_,_| Ok(json!([
|_,_,_| Ok(json!([
{"subdir": "datastore"},
])),
ObjectSchema::new("Directory index.")))

View File

@ -15,7 +15,11 @@ pub fn get() -> ApiMethod {
ObjectSchema::new("Directory index."))
}
fn get_datastore_list(_param: Value, _info: &ApiMethod) -> Result<Value, Error> {
fn get_datastore_list(
_param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
) -> Result<Value, Error> {
let config = datastore::config()?;
@ -31,7 +35,11 @@ pub fn post() -> ApiMethod {
)
}
fn create_datastore(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
fn create_datastore(
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
) -> Result<Value, Error> {
// fixme: locking ?
@ -64,7 +72,11 @@ pub fn delete() -> ApiMethod {
.required("name", StringSchema::new("Datastore name.")))
}
fn delete_datastore(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
fn delete_datastore(
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
) -> Result<Value, Error> {
println!("This is a test {}", param);
// fixme: locking ?

View File

@ -11,7 +11,7 @@ pub fn router() -> Router {
let route = Router::new()
.get(ApiMethod::new(
|_,_| Ok(json!([
|_,_,_| Ok(json!([
{"subdir": "network"},
{"subdir": "syslog"},
{"subdir": "time"},

View File

@ -51,7 +51,11 @@ fn read_etc_resolv_conf() -> Result<Value, Error> {
Ok(result)
}
fn update_dns(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
fn update_dns(
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
) -> Result<Value, Error> {
lazy_static! {
static ref MUTEX: Arc<Mutex<usize>> = Arc::new(Mutex::new(0));
@ -93,7 +97,11 @@ fn update_dns(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
Ok(Value::Null)
}
fn get_dns(_param: Value, _info: &ApiMethod) -> Result<Value, Error> {
fn get_dns(
_param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
) -> Result<Value, Error> {
read_etc_resolv_conf()
}

View File

@ -6,7 +6,11 @@ use crate::api::router::*;
use serde_json::{json, Value};
fn get_network_config(_param: Value, _info: &ApiMethod) -> Result<Value, Error> {
fn get_network_config(
_param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
) -> Result<Value, Error> {
Ok(json!({}))
}

View File

@ -72,7 +72,11 @@ fn dump_journal(
Ok((count, lines))
}
fn get_syslog(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
fn get_syslog(
param: Value,
_info: &ApiMethod,
rpcenv: &mut RpcEnvironment,
) -> Result<Value, Error> {
let (count, lines) = dump_journal(
param["start"].as_u64(),
@ -81,7 +85,7 @@ fn get_syslog(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
param["until"].as_str(),
param["service"].as_str())?;
//fixme: $restenv->set_result_attrib('total', $count);
rpcenv.set_result_attrib("total", Value::from(count));
Ok(json!(lines))
}

View File

@ -14,7 +14,11 @@ fn read_etc_localtime() -> Result<String, Error> {
Ok(line.trim().to_owned())
}
fn get_time(_param: Value, _info: &ApiMethod) -> Result<Value, Error> {
fn get_time(
_param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
) -> Result<Value, Error> {
let datetime = Local::now();
let offset = datetime.offset();
@ -32,7 +36,11 @@ extern "C" { fn tzset(); }
// Note:: this needs root rights ??
fn set_timezone(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
fn set_timezone(
param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
) -> Result<Value, Error> {
let timezone = tools::required_string_param(&param, "timezone")?;

View File

@ -6,7 +6,11 @@ use crate::api::router::*;
use serde_json::{json, Value};
fn get_subscription(_param: Value, _info: &ApiMethod) -> Result<Value, Error> {
fn get_subscription(
_param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
) -> Result<Value, Error> {
let url = "https://www.proxmox.com/en/proxmox-backup-server/pricing";
Ok(json!({

View File

@ -8,7 +8,11 @@ const PROXMOX_PKG_VERSION: &'static str = env!("PROXMOX_PKG_VERSION");
const PROXMOX_PKG_RELEASE: &'static str = env!("PROXMOX_PKG_RELEASE");
const PROXMOX_PKG_REPOID: &'static str = env!("PROXMOX_PKG_REPOID");
fn get_version(_param: Value, _info: &ApiMethod) -> Result<Value, Error> {
fn get_version(
_param: Value,
_info: &ApiMethod,
_rpcenv: &mut RpcEnvironment,
) -> Result<Value, Error> {
Ok(json!({
"version": PROXMOX_PKG_VERSION,