mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-04 15:40:27 +00:00
proxmox-api: move impl ApiMethod to lib.rs
This commit is contained in:
parent
446ee31466
commit
c1ffee0901
@ -20,6 +20,8 @@ pub mod router;
|
||||
pub mod rpc_environment;
|
||||
pub mod schema;
|
||||
|
||||
use schema::{ObjectSchema, Schema};
|
||||
|
||||
#[doc(inline)]
|
||||
pub use const_regex::ConstRegexPattern;
|
||||
|
||||
@ -104,6 +106,19 @@ pub enum ApiHandler {
|
||||
AsyncHttp(ApiAsyncHttpHandlerFn),
|
||||
}
|
||||
|
||||
const NULL_SCHEMA: Schema = Schema::Null;
|
||||
|
||||
fn dummy_handler_fn(
|
||||
_arg: Value,
|
||||
_method: &ApiMethod,
|
||||
_env: &mut dyn RpcEnvironment,
|
||||
) -> Result<Value, Error> {
|
||||
// do nothing
|
||||
Ok(Value::Null)
|
||||
}
|
||||
|
||||
const DUMMY_HANDLER: ApiHandler = ApiHandler::Sync(&dummy_handler_fn);
|
||||
|
||||
/// 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
|
||||
@ -129,3 +144,43 @@ impl std::fmt::Debug for ApiMethod {
|
||||
write!(f, "}}")
|
||||
}
|
||||
}
|
||||
|
||||
impl ApiMethod {
|
||||
pub const fn new(handler: &'static ApiHandler, parameters: &'static ObjectSchema) -> Self {
|
||||
Self {
|
||||
parameters,
|
||||
handler,
|
||||
returns: &NULL_SCHEMA,
|
||||
protected: false,
|
||||
reload_timezone: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn new_dummy(parameters: &'static ObjectSchema) -> Self {
|
||||
Self {
|
||||
parameters,
|
||||
handler: &DUMMY_HANDLER,
|
||||
returns: &NULL_SCHEMA,
|
||||
protected: false,
|
||||
reload_timezone: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn returns(mut self, schema: &'static Schema) -> Self {
|
||||
self.returns = schema;
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub const fn protected(mut self, protected: bool) -> Self {
|
||||
self.protected = protected;
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub const fn reload_timezone(mut self, reload_timezone: bool) -> Self {
|
||||
self.reload_timezone = reload_timezone;
|
||||
|
||||
self
|
||||
}
|
||||
}
|
||||
|
@ -1,64 +1,8 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use failure::Error;
|
||||
use hyper::Method;
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::schema::{ObjectSchema, Schema};
|
||||
use crate::{ApiHandler, ApiMethod, RpcEnvironment};
|
||||
|
||||
const NULL_SCHEMA: Schema = Schema::Null;
|
||||
|
||||
fn dummy_handler_fn(
|
||||
_arg: Value,
|
||||
_method: &ApiMethod,
|
||||
_env: &mut dyn RpcEnvironment,
|
||||
) -> Result<Value, Error> {
|
||||
// do nothing
|
||||
Ok(Value::Null)
|
||||
}
|
||||
|
||||
const DUMMY_HANDLER: ApiHandler = ApiHandler::Sync(&dummy_handler_fn);
|
||||
|
||||
impl ApiMethod {
|
||||
pub const fn new(handler: &'static ApiHandler, parameters: &'static ObjectSchema) -> Self {
|
||||
Self {
|
||||
parameters,
|
||||
handler,
|
||||
returns: &NULL_SCHEMA,
|
||||
protected: false,
|
||||
reload_timezone: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn new_dummy(parameters: &'static ObjectSchema) -> Self {
|
||||
Self {
|
||||
parameters,
|
||||
handler: &DUMMY_HANDLER,
|
||||
returns: &NULL_SCHEMA,
|
||||
protected: false,
|
||||
reload_timezone: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn returns(mut self, schema: &'static Schema) -> Self {
|
||||
self.returns = schema;
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub const fn protected(mut self, protected: bool) -> Self {
|
||||
self.protected = protected;
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub const fn reload_timezone(mut self, reload_timezone: bool) -> Self {
|
||||
self.reload_timezone = reload_timezone;
|
||||
|
||||
self
|
||||
}
|
||||
}
|
||||
use crate::ApiMethod;
|
||||
|
||||
pub type SubdirMap = &'static [(&'static str, &'static Router)];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user