api: pass RpcEnvirnment to api handlers
This commit is contained in:
@ -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.")))
|
||||
|
@ -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"},
|
||||
|
@ -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.")))
|
||||
|
@ -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 ?
|
||||
|
@ -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"},
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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!({}))
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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(¶m, "timezone")?;
|
||||
|
||||
|
@ -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!({
|
||||
|
@ -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,
|
||||
|
Reference in New Issue
Block a user