]> git.proxmox.com Git - proxmox-backup.git/commitdiff
first api macro usage test/example
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 27 Nov 2019 09:05:37 +0000 (10:05 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 27 Nov 2019 09:05:37 +0000 (10:05 +0100)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Cargo.toml
src/api2/access.rs

index 648c98068956ca996416e1eee1106da402ca93ed..bf6b76d7a90acd1175a2d36f9beaa0ef127892ea 100644 (file)
@@ -28,7 +28,7 @@ openssl = "0.10"
 pam = "0.7"
 pam-sys = "0.5"
 pin-utils = "0.1.0-alpha"
-proxmox = { git = "ssh://gitolite3@proxdev.maurer-it.com/rust/proxmox", version = "0.1", features = [ "sortable-macro" ] }
+proxmox = { git = "ssh://gitolite3@proxdev.maurer-it.com/rust/proxmox", version = "0.1", features = [ "sortable-macro", "api-macro" ] }
 regex = "1.0"
 serde = { version = "1.0", features = ["derive"] }
 serde_json = "1.0"
index e7ba4790277a6e284b4ac540d42bb3524e6613c1..10d53389f9fdacc10c36d4fc19b94738bd8acc77 100644 (file)
@@ -2,11 +2,11 @@ use failure::*;
 
 use serde_json::{json, Value};
 
-use proxmox::{sortable, identity};
+use proxmox::sortable;
 use proxmox::api::{http_err, list_subdirs_api_method};
-use proxmox::api::{ApiHandler, ApiMethod, Router, RpcEnvironment};
+use proxmox::api::{ApiMethod, Router, RpcEnvironment};
 use proxmox::api::router::SubdirMap;
-use proxmox::api::schema::*;
+use proxmox::api::api;
 
 use crate::tools;
 use crate::tools::ticket::*;
@@ -36,6 +36,40 @@ fn authenticate_user(username: &str, password: &str) -> Result<(), Error> {
     bail!("inavlid credentials");
 }
 
+#[api]
+#[input({
+    properties: {
+        username: {
+            type: String,
+            description: "User name.",
+            max_length: 64,
+        },
+        password: {
+            type: String,
+            description: "The secret password. This can also be a valid ticket.",
+        },
+    },
+})]
+#[returns({
+    properties: {
+        username: {
+            type: String,
+            description: "User name.",
+        },
+        ticket: {
+            type: String,
+            description: "Auth ticket.",
+        },
+        CSRFPreventionToken: {
+            type: String,
+            description: "Cross Site Request Forgery Prevention Token.",
+        },
+    },
+})]
+#[protected]
+/// Create or verify authentication ticket.
+///
+/// Returns: An authentication ticket with additional infos.
 fn create_ticket(
     param: Value,
     _info: &ApiMethod,
@@ -72,51 +106,7 @@ fn create_ticket(
 const SUBDIRS: SubdirMap = &[
     (
         "ticket", &Router::new()
-            .post(
-                &ApiMethod::new(
-                    &ApiHandler::Sync(&create_ticket),
-                    &ObjectSchema::new(
-                        "Create or verify authentication ticket.",
-                        &sorted!([
-                            (
-                                "username",
-                                false,
-                                &StringSchema::new("User name.")
-                                    .max_length(64)
-                                    .schema()
-                            ),
-                            (
-                                "password",
-                                false,
-                                &StringSchema::new("The secret password. This can also be a valid ticket.")
-                                    .schema()
-                            ),
-                        ]),
-                    )
-                ).returns(
-                    &ObjectSchema::new(
-                        "Returns authentication ticket with additional infos.",
-                        &sorted!([
-                            (
-                                "username",
-                                false,
-                                &StringSchema::new("User name.").schema()
-                            ),
-                            (
-                                "ticket",
-                                false,
-                                &StringSchema::new("Auth ticket.").schema()
-                            ),
-                            (
-                                "CSRFPreventionToken",
-                                false,
-                                &StringSchema::new("Cross Site Request Forgery Prevention Token.")
-                                    .schema()
-                            ),
-                        ]),
-                    ).schema()
-                ).protected(true)
-            )
+            .post(&API_METHOD_CREATE_TICKET)
     )
 ];