all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Christoph Heiss <c.heiss@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [PATCH proxmox-backup 1/2] manager: user: make 'user generate-token' accept --output-format
Date: Thu, 16 Jul 2026 12:29:56 +0200	[thread overview]
Message-ID: <20260716103108.724902-2-c.heiss@proxmox.com> (raw)
In-Reply-To: <20260716103108.724902-1-c.heiss@proxmox.com>

Needs a small wrapper (like most other commands) to parse the option and
print the result formatted appropriately.

Before, when invoking 'proxmox-backup-manager user generate-token [..]',
the output would be a mix of human-readable and machine-readable:

    Result: {
      "tokenid": "root@pam!my-token",
      "value": ".."
    }

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
Ran across this while working on something else, definitely worth
fixing.

 src/bin/proxmox_backup_manager/user.rs | 39 ++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)

diff --git a/src/bin/proxmox_backup_manager/user.rs b/src/bin/proxmox_backup_manager/user.rs
index 87c1f4394..a429823de 100644
--- a/src/bin/proxmox_backup_manager/user.rs
+++ b/src/bin/proxmox_backup_manager/user.rs
@@ -6,7 +6,7 @@ use std::collections::HashMap;
 use proxmox_router::{ApiHandler, RpcEnvironment, cli::*};
 use proxmox_schema::api;
 
-use pbs_api_types::{ACL_PATH_SCHEMA, Authid, Userid};
+use pbs_api_types::{ACL_PATH_SCHEMA, Authid, Tokenname, Userid};
 
 use proxmox_backup::api2;
 
@@ -101,6 +101,41 @@ fn list_tokens(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, E
     Ok(Value::Null)
 }
 
+#[api(
+    input: {
+        properties: {
+            "output-format": {
+                schema: OUTPUT_FORMAT,
+                optional: true,
+            },
+            userid: {
+                type: Userid,
+            },
+            "token-name": {
+                type: Tokenname,
+            },
+        }
+    }
+)]
+/// Generate a new API token with given metadata
+fn generate_token(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
+    let output_format = get_output_format(&param);
+
+    let info = &api2::access::user::API_METHOD_GENERATE_TOKEN;
+    let mut data = match info.handler {
+        ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
+        _ => unreachable!(),
+    };
+
+    let options = default_table_format_options()
+        .column(ColumnConfig::new("tokenid"))
+        .column(ColumnConfig::new("value"));
+
+    format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
+
+    Ok(Value::Null)
+}
+
 #[api(
     input: {
         properties: {
@@ -219,7 +254,7 @@ pub fn user_commands() -> CommandLineInterface {
         )
         .insert(
             "generate-token",
-            CliCommand::new(&api2::access::user::API_METHOD_GENERATE_TOKEN)
+            CliCommand::new(&API_METHOD_GENERATE_TOKEN)
                 .arg_param(&["userid", "token-name"])
                 .completion_cb("userid", pbs_config::user::complete_userid),
         )
-- 
2.54.0





  reply	other threads:[~2026-07-16 10:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-16 10:29 [PATCH proxmox-backup 0/2] manager: user: improve 'generate-token', implement 'update-token' Christoph Heiss
2026-07-16 10:29 ` Christoph Heiss [this message]
2026-07-16 10:29 ` [PATCH proxmox-backup 2/2] manager: user: add 'user update-token' command Christoph Heiss

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260716103108.724902-2-c.heiss@proxmox.com \
    --to=c.heiss@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal