cleanup api3 structure
This commit is contained in:
parent
678d72df6b
commit
6ce50400c5
34
src/api3.rs
34
src/api3.rs
|
@ -1,11 +1,14 @@
|
|||
use failure::*;
|
||||
use std::collections::HashMap;
|
||||
//use std::collections::HashMap;
|
||||
|
||||
|
||||
use crate::api::schema::*;
|
||||
use crate::api::router::*;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
mod config;
|
||||
mod version;
|
||||
|
||||
fn test_sync_api_handler(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
|
||||
println!("This is a test {}", param);
|
||||
|
||||
|
@ -24,20 +27,6 @@ fn test_sync_api_handler(param: Value, _info: &ApiMethod) -> Result<Value, Error
|
|||
Ok(json!(null))
|
||||
}
|
||||
|
||||
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> {
|
||||
|
||||
Ok(json!({
|
||||
"version": PROXMOX_PKG_VERSION,
|
||||
"release": PROXMOX_PKG_RELEASE,
|
||||
"repoid": PROXMOX_PKG_REPOID
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn router() -> Router {
|
||||
|
||||
let route4 = Router::new()
|
||||
|
@ -62,16 +51,17 @@ pub fn router() -> Router {
|
|||
let nodes = Router::new()
|
||||
.match_all("node", nodeinfo);
|
||||
|
||||
let version = Router::new()
|
||||
.get(ApiMethod::new(
|
||||
get_version,
|
||||
ObjectSchema::new("Proxmox Backup Server API version.")));
|
||||
|
||||
let route = Router::new()
|
||||
let route = Router::new()
|
||||
.get(ApiMethod::new(
|
||||
get_version,
|
||||
|_,_| Ok(json!([
|
||||
{"subdir": "config"},
|
||||
{"subdir": "version"},
|
||||
{"subdir": "nodes"}
|
||||
])),
|
||||
ObjectSchema::new("Directory index.")))
|
||||
.subdir("version", version)
|
||||
.subdir("config", config::router())
|
||||
.subdir("version", version::router())
|
||||
.subdir("nodes", nodes);
|
||||
|
||||
route
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
use failure::*;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::api::schema::*;
|
||||
use crate::api::router::*;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
mod datastore;
|
||||
|
||||
pub fn router() -> Router {
|
||||
|
||||
let route = Router::new()
|
||||
.get(ApiMethod::new(
|
||||
|_,_| Ok(json!([
|
||||
{"subdir": "datastore"}
|
||||
])),
|
||||
ObjectSchema::new("Directory index.")))
|
||||
.subdir("datastore", datastore::router());
|
||||
|
||||
|
||||
route
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
use failure::*;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::api::schema::*;
|
||||
use crate::api::router::*;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
fn datastore_list(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.")));
|
||||
|
||||
route
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
use failure::*;
|
||||
|
||||
use crate::api::schema::*;
|
||||
use crate::api::router::*;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
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> {
|
||||
|
||||
Ok(json!({
|
||||
"version": PROXMOX_PKG_VERSION,
|
||||
"release": PROXMOX_PKG_RELEASE,
|
||||
"repoid": PROXMOX_PKG_REPOID
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn router() -> Router {
|
||||
|
||||
let route = Router::new()
|
||||
.get(ApiMethod::new(
|
||||
get_version,
|
||||
ObjectSchema::new("Proxmox Backup Server API version.")));
|
||||
|
||||
route
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
use failure::*;
|
||||
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::fs::{OpenOptions};
|
||||
use std::io::Read;
|
||||
|
||||
//use std::sync::Arc;
|
||||
|
@ -32,23 +32,23 @@ fn init() -> SectionConfig {
|
|||
config
|
||||
}
|
||||
|
||||
const datastore_cfg: &str = "/etc/proxmox-backup/datastore.cfg";
|
||||
const DATASTORE_CFG_FILENAME: &str = "/etc/proxmox-backup/datastore.cfg";
|
||||
|
||||
fn config() -> Result<SectionConfigData, Error> {
|
||||
|
||||
let mut file = match OpenOptions::new()
|
||||
.create(true)
|
||||
.write(true)
|
||||
.open(datastore_cfg) {
|
||||
.open(DATASTORE_CFG_FILENAME) {
|
||||
Ok(file) => file,
|
||||
Err(err) => bail!("Unable to open '{}' - {}",
|
||||
datastore_cfg, err),
|
||||
DATASTORE_CFG_FILENAME, err),
|
||||
};
|
||||
|
||||
let mut contents = String::new();
|
||||
file.read_to_string(&mut contents).unwrap();
|
||||
|
||||
CONFIG.parse(datastore_cfg, &contents)
|
||||
CONFIG.parse(DATASTORE_CFG_FILENAME, &contents)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -49,4 +49,3 @@ pub mod storage {
|
|||
pub mod getopts;
|
||||
|
||||
pub mod api3;
|
||||
|
||||
|
|
Loading…
Reference in New Issue