]> git.proxmox.com Git - proxmox-backup.git/commitdiff
api: add world accessible ping dummy endpoint
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 2 Oct 2020 11:12:18 +0000 (13:12 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Sat, 24 Oct 2020 17:12:14 +0000 (19:12 +0200)
This is indented to be used for the PVE storage library, replacing
the missuse of the much more expensive status API call.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/api2.rs
src/api2/ping.rs [new file with mode: 0644]

index 85d29ed20f989488fe9f304df19ea2209afb969e..27ef2975156485394f24b1e282aa4d466ad7c3fa 100644 (file)
@@ -7,6 +7,7 @@ pub mod reader;
 pub mod status;
 pub mod types;
 pub mod version;
+pub mod ping;
 pub mod pull;
 mod helpers;
 
@@ -22,6 +23,7 @@ pub const SUBDIRS: SubdirMap = &[
     ("backup", &backup::ROUTER),
     ("config", &config::ROUTER),
     ("nodes", &NODES_ROUTER),
+    ("ping", &ping::ROUTER),
     ("pull", &pull::ROUTER),
     ("reader", &reader::ROUTER),
     ("status", &status::ROUTER),
diff --git a/src/api2/ping.rs b/src/api2/ping.rs
new file mode 100644 (file)
index 0000000..087b137
--- /dev/null
@@ -0,0 +1,29 @@
+use anyhow::{Error};
+use serde_json::{json, Value};
+
+use proxmox::api::{api, Router, Permission};
+
+#[api(
+    returns: {
+        description: "Dummy ping",
+        type: Object,
+        properties: {
+            pong: {
+                description: "Always true",
+                type: bool,
+            }
+        }
+    },
+    access: {
+        description: "Anyone can access this, because it's used for a cheap check if the API daemon is online.",
+        permission: &Permission::World,
+    }
+)]
+/// Dummy method which replies with `{ "pong": True }`
+fn ping() -> Result<Value, Error> {
+    Ok(json!({
+        "pong": true,
+    }))
+}
+pub const ROUTER: Router = Router::new()
+    .get(&API_METHOD_PING);