]> git.proxmox.com Git - proxmox-backup.git/commitdiff
move src/api_schema/config.rs -> src/server/config.rs
authorDietmar Maurer <dietmar@proxmox.com>
Fri, 22 Nov 2019 08:23:03 +0000 (09:23 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 22 Nov 2019 08:23:03 +0000 (09:23 +0100)
src/api_schema.rs
src/api_schema/config.rs [deleted file]
src/bin/proxmox-backup-api.rs
src/bin/proxmox-backup-proxy.rs
src/server.rs
src/server/config.rs [new file with mode: 0644]
src/server/rest.rs

index 27ef3194da31765fc0b1fe5e57f3e9f62b080c47..8069fd091fd054e25069e19e5487c3a72c657fc3 100644 (file)
@@ -8,5 +8,4 @@
 //! hierarchy of API entries, and provides ways to find an API
 //! definition by path.
 
-pub mod config;
 pub mod format;
diff --git a/src/api_schema/config.rs b/src/api_schema/config.rs
deleted file mode 100644 (file)
index d9aa076..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-use std::collections::HashMap;
-use std::path::{PathBuf};
-
-use hyper::Method;
-
-use proxmox::api::{ApiMethod, Router, RpcEnvironmentType};
-
-pub struct ApiConfig {
-    basedir: PathBuf,
-    router: &'static Router,
-    aliases: HashMap<String, PathBuf>,
-    env_type: RpcEnvironmentType,
-}
-
-impl ApiConfig {
-
-    pub fn new<B: Into<PathBuf>>(basedir: B, router: &'static Router, env_type: RpcEnvironmentType) -> Self {
-        Self {
-            basedir: basedir.into(),
-            router,
-            aliases: HashMap::new(),
-            env_type,
-        }
-    }
-
-    pub fn find_method(
-        &self,
-        components: &[&str],
-        method: Method,
-        uri_param: &mut HashMap<String, String>,
-    ) -> Option<&'static ApiMethod> {
-
-        self.router.find_method(components, method, uri_param)
-    }
-
-    pub fn find_alias(&self, components: &[&str]) -> PathBuf {
-
-        let mut prefix = String::new();
-        let mut filename = self.basedir.clone();
-        let comp_len = components.len();
-        if comp_len >= 1 {
-            prefix.push_str(components[0]);
-            if let Some(subdir) = self.aliases.get(&prefix) {
-                filename.push(subdir);
-                for i in 1..comp_len { filename.push(components[i]) }
-            } else {
-                for i in 0..comp_len { filename.push(components[i]) }
-            }
-        }
-        filename
-    }
-
-    pub fn add_alias<S, P>(&mut self, alias: S, path: P)
-        where S: Into<String>,
-              P: Into<PathBuf>,
-    {
-        self.aliases.insert(alias.into(), path.into());
-    }
-
-    pub fn env_type(&self) -> RpcEnvironmentType {
-        self.env_type
-    }
-}
index bcaa2122bc8a2e087a9b24dbc09ebd5a09ef08da..64ca7c42b892955de205808e70465bffa8a68450 100644 (file)
@@ -5,7 +5,7 @@ use proxmox::tools::try_block;
 use proxmox::api::RpcEnvironmentType;
 
 //use proxmox_backup::tools;
-use proxmox_backup::api_schema::config::*;
+//use proxmox_backup::api_schema::config::*;
 use proxmox_backup::server::rest::*;
 use proxmox_backup::server;
 use proxmox_backup::tools::daemon;
@@ -43,7 +43,7 @@ async fn run() -> Result<(), Error> {
     }
     let _ = csrf_secret(); // load with lazy_static
 
-    let config = ApiConfig::new(
+    let config = server::ApiConfig::new(
         buildcfg::JS_DIR, &proxmox_backup::api2::ROUTER, RpcEnvironmentType::PRIVILEGED);
  
     let rest_server = RestServer::new(config);
index f7d346bc7fae30d7d89da20883d94117ef276ef6..b6e23883b8ed885f3a51a0bfcc9ea89e3246a08d 100644 (file)
@@ -12,8 +12,7 @@ use proxmox_backup::configdir;
 use proxmox_backup::buildcfg;
 use proxmox_backup::server;
 use proxmox_backup::tools::daemon;
-use proxmox_backup::api_schema::config::*;
-use proxmox_backup::server::rest::*;
+use proxmox_backup::server::{ApiConfig, rest::*};
 use proxmox_backup::auth_helpers::*;
 
 #[tokio::main]
index 21c0885a8e7c281ce6772418baadcf36bc6e7be9..2712e929feb1c16ad9bab7e6d576d3ceee4e06cb 100644 (file)
@@ -22,6 +22,9 @@ pub use worker_task::*;
 mod h2service;
 pub use h2service::*;
 
+pub mod config;
+pub use config::*;
+
 pub mod formatter;
 
 #[macro_use]
diff --git a/src/server/config.rs b/src/server/config.rs
new file mode 100644 (file)
index 0000000..d9aa076
--- /dev/null
@@ -0,0 +1,63 @@
+use std::collections::HashMap;
+use std::path::{PathBuf};
+
+use hyper::Method;
+
+use proxmox::api::{ApiMethod, Router, RpcEnvironmentType};
+
+pub struct ApiConfig {
+    basedir: PathBuf,
+    router: &'static Router,
+    aliases: HashMap<String, PathBuf>,
+    env_type: RpcEnvironmentType,
+}
+
+impl ApiConfig {
+
+    pub fn new<B: Into<PathBuf>>(basedir: B, router: &'static Router, env_type: RpcEnvironmentType) -> Self {
+        Self {
+            basedir: basedir.into(),
+            router,
+            aliases: HashMap::new(),
+            env_type,
+        }
+    }
+
+    pub fn find_method(
+        &self,
+        components: &[&str],
+        method: Method,
+        uri_param: &mut HashMap<String, String>,
+    ) -> Option<&'static ApiMethod> {
+
+        self.router.find_method(components, method, uri_param)
+    }
+
+    pub fn find_alias(&self, components: &[&str]) -> PathBuf {
+
+        let mut prefix = String::new();
+        let mut filename = self.basedir.clone();
+        let comp_len = components.len();
+        if comp_len >= 1 {
+            prefix.push_str(components[0]);
+            if let Some(subdir) = self.aliases.get(&prefix) {
+                filename.push(subdir);
+                for i in 1..comp_len { filename.push(components[i]) }
+            } else {
+                for i in 0..comp_len { filename.push(components[i]) }
+            }
+        }
+        filename
+    }
+
+    pub fn add_alias<S, P>(&mut self, alias: S, path: P)
+        where S: Into<String>,
+              P: Into<PathBuf>,
+    {
+        self.aliases.insert(alias.into(), path.into());
+    }
+
+    pub fn env_type(&self) -> RpcEnvironmentType {
+        self.env_type
+    }
+}
index 55e010b642a87c477d16a5c33a247a5bc3f95a97..36a4117e1bd4d5562e5ffd46d894de72c698e603 100644 (file)
@@ -23,8 +23,9 @@ use proxmox::api::schema::{parse_simple_value, verify_json_object, parse_paramet
 
 use super::environment::RestEnvironment;
 use super::formatter::*;
+use super::ApiConfig;
+
 use crate::auth_helpers::*;
-use crate::api_schema::config::ApiConfig;
 use crate::tools;
 
 extern "C"  { fn tzset(); }