2018-11-16 12:14:11 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate apitest;
|
|
|
|
|
|
|
|
use std::collections::HashMap;
|
2018-11-20 15:54:29 +00:00
|
|
|
use std::sync::Arc;
|
2018-11-16 12:14:11 +00:00
|
|
|
|
|
|
|
use apitest::api::schema::*;
|
2018-11-15 16:07:10 +00:00
|
|
|
use apitest::api::router::*;
|
|
|
|
use apitest::api::config::*;
|
|
|
|
use apitest::api::server::*;
|
2018-11-16 12:14:11 +00:00
|
|
|
use apitest::getopts;
|
2018-10-31 09:42:14 +00:00
|
|
|
|
2018-11-15 09:14:08 +00:00
|
|
|
//use failure::*;
|
|
|
|
use lazy_static::lazy_static;
|
|
|
|
|
2018-11-15 07:18:48 +00:00
|
|
|
use futures::future::Future;
|
2018-11-09 07:22:54 +00:00
|
|
|
|
2018-11-15 07:18:48 +00:00
|
|
|
use hyper;
|
2018-10-31 09:42:14 +00:00
|
|
|
|
2018-10-30 09:04:30 +00:00
|
|
|
fn main() {
|
2018-11-17 08:57:26 +00:00
|
|
|
println!("Proxmox REST Server example.");
|
2018-10-30 09:04:30 +00:00
|
|
|
|
2018-11-22 10:23:49 +00:00
|
|
|
let prop = Arc::new(ApiString!{ optional => true });
|
2018-11-16 12:14:11 +00:00
|
|
|
let schema = parameter!{
|
2018-11-22 10:23:49 +00:00
|
|
|
name1 => prop.clone(),
|
|
|
|
name2 => prop.clone()
|
2018-11-16 12:14:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let args: Vec<String> = std::env::args().skip(1).collect();
|
2018-11-18 09:09:13 +00:00
|
|
|
match getopts::parse_arguments(&args, &vec![], &schema) {
|
2018-11-17 08:57:26 +00:00
|
|
|
Ok((options, rest)) => {
|
|
|
|
println!("Got Options: {}", options);
|
|
|
|
println!("Remaining Arguments: {:?}", rest);
|
|
|
|
}
|
|
|
|
Err(err) => {
|
|
|
|
eprintln!("Unable to parse arguments:\n{}", err);
|
|
|
|
std::process::exit(-1);
|
|
|
|
}
|
|
|
|
}
|
2018-11-16 12:14:11 +00:00
|
|
|
|
2018-10-31 09:42:14 +00:00
|
|
|
let addr = ([127, 0, 0, 1], 8007).into();
|
|
|
|
|
2018-11-14 10:57:01 +00:00
|
|
|
lazy_static!{
|
2018-11-15 10:46:13 +00:00
|
|
|
static ref ROUTER: Router = apitest::api3::router();
|
2018-11-14 10:57:01 +00:00
|
|
|
}
|
2018-11-13 13:47:03 +00:00
|
|
|
|
2018-11-15 07:18:48 +00:00
|
|
|
let mut config = ApiConfig::new("/var/www", &ROUTER);
|
2018-11-14 12:22:33 +00:00
|
|
|
|
|
|
|
// add default dirs which includes jquery and bootstrap
|
|
|
|
// my $base = '/usr/share/libpve-http-server-perl';
|
|
|
|
// add_dirs($self->{dirs}, '/css/' => "$base/css/");
|
|
|
|
// add_dirs($self->{dirs}, '/js/' => "$base/js/");
|
|
|
|
// add_dirs($self->{dirs}, '/fonts/' => "$base/fonts/");
|
2018-11-15 07:18:48 +00:00
|
|
|
config.add_alias("novnc", "/usr/share/novnc-pve");
|
|
|
|
config.add_alias("extjs", "/usr/share/javascript/extjs");
|
|
|
|
config.add_alias("fontawesome", "/usr/share/fonts-font-awesome");
|
|
|
|
config.add_alias("xtermjs", "/usr/share/pve-xtermjs");
|
|
|
|
config.add_alias("widgettoolkit", "/usr/share/javascript/proxmox-widget-toolkit");
|
2018-11-13 13:47:03 +00:00
|
|
|
|
2018-11-15 07:18:48 +00:00
|
|
|
let rest_server = RestServer::new(config);
|
2018-10-31 09:42:14 +00:00
|
|
|
|
2018-11-15 07:18:48 +00:00
|
|
|
let server = hyper::Server::bind(&addr)
|
|
|
|
.serve(rest_server)
|
2018-10-31 09:42:14 +00:00
|
|
|
.map_err(|e| eprintln!("server error: {}", e));
|
|
|
|
|
2018-11-18 14:01:19 +00:00
|
|
|
|
2018-10-31 09:42:14 +00:00
|
|
|
// Run this server for... forever!
|
|
|
|
hyper::rt::run(server);
|
2018-10-30 09:04:30 +00:00
|
|
|
}
|