1 use std
::collections
::HashMap
;
2 use std
::path
::{PathBuf}
;
6 use handlebars
::Handlebars
;
8 use proxmox
::api
::{ApiMethod, Router, RpcEnvironmentType}
;
10 pub struct ApiConfig
{
12 router
: &'
static Router
,
13 aliases
: HashMap
<String
, PathBuf
>,
14 env_type
: RpcEnvironmentType
,
15 pub templates
: Handlebars
<'
static>,
20 pub fn new
<B
: Into
<PathBuf
>>(basedir
: B
, router
: &'
static Router
, env_type
: RpcEnvironmentType
) -> Result
<Self, Error
> {
21 let mut templates
= Handlebars
::new();
22 let basedir
= basedir
.into();
23 templates
.register_template_file("index", basedir
.join("index.hbs"))?
;
27 aliases
: HashMap
::new(),
37 uri_param
: &mut HashMap
<String
, String
>,
38 ) -> Option
<&'
static ApiMethod
> {
40 self.router
.find_method(components
, method
, uri_param
)
43 pub fn find_alias(&self, components
: &[&str]) -> PathBuf
{
45 let mut prefix
= String
::new();
46 let mut filename
= self.basedir
.clone();
47 let comp_len
= components
.len();
49 prefix
.push_str(components
[0]);
50 if let Some(subdir
) = self.aliases
.get(&prefix
) {
51 filename
.push(subdir
);
52 for i
in 1..comp_len { filename.push(components[i]) }
54 for i
in 0..comp_len { filename.push(components[i]) }
60 pub fn add_alias
<S
, P
>(&mut self, alias
: S
, path
: P
)
61 where S
: Into
<String
>,
64 self.aliases
.insert(alias
.into(), path
.into());
67 pub fn env_type(&self) -> RpcEnvironmentType
{