api: move ApiMethod from router to top level

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2019-11-21 13:43:10 +01:00
parent c0266a17cd
commit c38d18484d
2 changed files with 29 additions and 29 deletions

View File

@ -1,5 +1,6 @@
//! Proxmox API module. This provides utilities for HTTP and command line APIs.
use std::fmt;
use std::future::Future;
use failure::Error;
@ -16,7 +17,7 @@ pub mod schema;
pub use rpc_environment::{RpcEnvironment, RpcEnvironmentType};
#[doc(inline)]
pub use router::ApiMethod;
pub use router::Router;
#[doc(inline)]
pub use error::HttpError;
@ -46,3 +47,29 @@ pub enum ApiHandler {
Sync(ApiHandlerFn),
Async(ApiAsyncHandlerFn),
}
/// This struct defines synchronous API call which returns the restulkt as json `Value`
pub struct ApiMethod {
/// The protected flag indicates that the provides function should be forwarded
/// to the deaemon running in priviledged mode.
pub protected: bool,
/// This flag indicates that the provided method may change the local timezone, so the server
/// should do a tzset afterwards
pub reload_timezone: bool,
/// Parameter type Schema
pub parameters: &'static schema::ObjectSchema,
/// Return type Schema
pub returns: &'static schema::Schema,
/// Handler function
pub handler: &'static ApiHandler,
}
impl std::fmt::Debug for ApiMethod {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ApiMethod {{ ")?;
write!(f, " parameters: {:?}", self.parameters)?;
write!(f, " returns: {:?}", self.returns)?;
write!(f, " handler: {:p}", &self.handler)?;
write!(f, "}}")
}
}

View File

@ -1,38 +1,11 @@
use std::collections::HashMap;
use std::fmt;
use failure::Error;
use hyper::Method;
use serde_json::Value;
use crate::schema::{ObjectSchema, Schema};
use crate::{ApiHandler, RpcEnvironment};
/// This struct defines synchronous API call which returns the restulkt as json `Value`
pub struct ApiMethod {
/// The protected flag indicates that the provides function should be forwarded
/// to the deaemon running in priviledged mode.
pub protected: bool,
/// This flag indicates that the provided method may change the local timezone, so the server
/// should do a tzset afterwards
pub reload_timezone: bool,
/// Parameter type Schema
pub parameters: &'static ObjectSchema,
/// Return type Schema
pub returns: &'static Schema,
/// Handler function
pub handler: &'static ApiHandler,
}
impl std::fmt::Debug for ApiMethod {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ApiMethod {{ ")?;
write!(f, " parameters: {:?}", self.parameters)?;
write!(f, " returns: {:?}", self.returns)?;
write!(f, " handler: {:p}", &self.handler)?;
write!(f, "}}")
}
}
use crate::{ApiHandler, ApiMethod, RpcEnvironment};
const NULL_SCHEMA: Schema = Schema::Null;