public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH backup] api: add world accessible ping dummy endpoint
@ 2020-10-05 14:57 Thomas Lamprecht
  2020-10-21 18:32 ` Thomas Lamprecht
  2020-10-24 17:14 ` [pbs-devel] applied: " Thomas Lamprecht
  0 siblings, 2 replies; 5+ messages in thread
From: Thomas Lamprecht @ 2020-10-05 14:57 UTC (permalink / raw)
  To: pbs-devel

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>
---

I initially thought about adding this to the proxmox-backup-client as command,
but it's not much of use there (user can just use the version command) and for
the PVE integration we can do a simple http request with LWP, which is much
cheaper than fork+exec the client there.

 src/api2.rs      |  2 ++
 src/api2/ping.rs | 29 +++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)
 create mode 100644 src/api2/ping.rs

diff --git a/src/api2.rs b/src/api2.rs
index 85d29ed2..27ef2975 100644
--- a/src/api2.rs
+++ b/src/api2.rs
@@ -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
index 00000000..087b1377
--- /dev/null
+++ b/src/api2/ping.rs
@@ -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);
-- 
2.27.0





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [pbs-devel] [PATCH backup] api: add world accessible ping dummy endpoint
  2020-10-05 14:57 [pbs-devel] [PATCH backup] api: add world accessible ping dummy endpoint Thomas Lamprecht
@ 2020-10-21 18:32 ` Thomas Lamprecht
  2020-10-22  8:18   ` Fabian Grünbichler
  2020-10-24 17:14 ` [pbs-devel] applied: " Thomas Lamprecht
  1 sibling, 1 reply; 5+ messages in thread
From: Thomas Lamprecht @ 2020-10-21 18:32 UTC (permalink / raw)
  To: pbs-devel

On 05.10.20 16:57, Thomas Lamprecht wrote:
> 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>
> ---
> 
> I initially thought about adding this to the proxmox-backup-client as command,
> but it's not much of use there (user can just use the version command) and for
> the PVE integration we can do a simple http request with LWP, which is much
> cheaper than fork+exec the client there.
> 

any objections to this? Else I'd apply it as is..

>  src/api2.rs      |  2 ++
>  src/api2/ping.rs | 29 +++++++++++++++++++++++++++++
>  2 files changed, 31 insertions(+)
>  create mode 100644 src/api2/ping.rs
> 
> diff --git a/src/api2.rs b/src/api2.rs
> index 85d29ed2..27ef2975 100644
> --- a/src/api2.rs
> +++ b/src/api2.rs
> @@ -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
> index 00000000..087b1377
> --- /dev/null
> +++ b/src/api2/ping.rs
> @@ -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);
> 





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [pbs-devel] [PATCH backup] api: add world accessible ping dummy endpoint
  2020-10-21 18:32 ` Thomas Lamprecht
@ 2020-10-22  8:18   ` Fabian Grünbichler
  2020-10-22 10:34     ` Thomas Lamprecht
  0 siblings, 1 reply; 5+ messages in thread
From: Fabian Grünbichler @ 2020-10-22  8:18 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion

On October 21, 2020 8:32 pm, Thomas Lamprecht wrote:
> On 05.10.20 16:57, Thomas Lamprecht wrote:
>> 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>
>> ---
>> 
>> I initially thought about adding this to the proxmox-backup-client as command,
>> but it's not much of use there (user can just use the version command) and for
>> the PVE integration we can do a simple http request with LWP, which is much
>> cheaper than fork+exec the client there.
>> 
> 
> any objections to this? Else I'd apply it as is..

LGTM, maybe besides that having a separate file for this instead of just 
inlining it into api2.rs seems overkill :-P

> 
>>  src/api2.rs      |  2 ++
>>  src/api2/ping.rs | 29 +++++++++++++++++++++++++++++
>>  2 files changed, 31 insertions(+)
>>  create mode 100644 src/api2/ping.rs
>> 
>> diff --git a/src/api2.rs b/src/api2.rs
>> index 85d29ed2..27ef2975 100644
>> --- a/src/api2.rs
>> +++ b/src/api2.rs
>> @@ -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
>> index 00000000..087b1377
>> --- /dev/null
>> +++ b/src/api2/ping.rs
>> @@ -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);
>> 
> 
> 
> 
> _______________________________________________
> pbs-devel mailing list
> pbs-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
> 
> 
> 




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [pbs-devel] [PATCH backup] api: add world accessible ping dummy endpoint
  2020-10-22  8:18   ` Fabian Grünbichler
@ 2020-10-22 10:34     ` Thomas Lamprecht
  0 siblings, 0 replies; 5+ messages in thread
From: Thomas Lamprecht @ 2020-10-22 10:34 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Fabian Grünbichler

On 22.10.20 10:18, Fabian Grünbichler wrote:
> On October 21, 2020 8:32 pm, Thomas Lamprecht wrote:
>> On 05.10.20 16:57, Thomas Lamprecht wrote:
>>> 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>
>>> ---
>>>
>>> I initially thought about adding this to the proxmox-backup-client as command,
>>> but it's not much of use there (user can just use the version command) and for
>>> the PVE integration we can do a simple http request with LWP, which is much
>>> cheaper than fork+exec the client there.
>>>
>>
>> any objections to this? Else I'd apply it as is..
> 
> LGTM, maybe besides that having a separate file for this instead of just 
> inlining it into api2.rs seems overkill :-P
> 

Thought so first too, but it made the top level API entry point quite a bit uglier,
more noisier, and as the separate file does not costs much I went for that way :)





^ permalink raw reply	[flat|nested] 5+ messages in thread

* [pbs-devel] applied: [PATCH backup] api: add world accessible ping dummy endpoint
  2020-10-05 14:57 [pbs-devel] [PATCH backup] api: add world accessible ping dummy endpoint Thomas Lamprecht
  2020-10-21 18:32 ` Thomas Lamprecht
@ 2020-10-24 17:14 ` Thomas Lamprecht
  1 sibling, 0 replies; 5+ messages in thread
From: Thomas Lamprecht @ 2020-10-24 17:14 UTC (permalink / raw)
  To: pbs-devel

On 05.10.20 16:57, Thomas Lamprecht wrote:
> 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>
> ---
> 
> I initially thought about adding this to the proxmox-backup-client as command,
> but it's not much of use there (user can just use the version command) and for
> the PVE integration we can do a simple http request with LWP, which is much
> cheaper than fork+exec the client there.
> 
>  src/api2.rs      |  2 ++
>  src/api2/ping.rs | 29 +++++++++++++++++++++++++++++
>  2 files changed, 31 insertions(+)
>  create mode 100644 src/api2/ping.rs
> 
>

applied




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-10-24 17:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-05 14:57 [pbs-devel] [PATCH backup] api: add world accessible ping dummy endpoint Thomas Lamprecht
2020-10-21 18:32 ` Thomas Lamprecht
2020-10-22  8:18   ` Fabian Grünbichler
2020-10-22 10:34     ` Thomas Lamprecht
2020-10-24 17:14 ` [pbs-devel] applied: " Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal