* [PATCH proxmox-backup 0/2] manager: user: improve 'generate-token', implement 'update-token'
@ 2026-07-16 10:29 Christoph Heiss
2026-07-16 10:29 ` [PATCH proxmox-backup 1/2] manager: user: make 'user generate-token' accept --output-format Christoph Heiss
2026-07-16 10:29 ` [PATCH proxmox-backup 2/2] manager: user: add 'user update-token' command Christoph Heiss
0 siblings, 2 replies; 3+ messages in thread
From: Christoph Heiss @ 2026-07-16 10:29 UTC (permalink / raw)
To: pbs-devel
Two small patches improving API token management via the
`proxmox-backup-manager user [..]` command a bit.
Both patches are pretty straight-forward and mostly boilerplate; calling
the underlying API method and formatting the result.
Christoph Heiss (2):
manager: user: make 'user generate-token' accept --output-format
manager: user: add 'user update-token' command
src/bin/proxmox_backup_manager/user.rs | 102 ++++++++++++++++++++++++-
1 file changed, 100 insertions(+), 2 deletions(-)
--
2.54.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH proxmox-backup 1/2] manager: user: make 'user generate-token' accept --output-format
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
2026-07-16 10:29 ` [PATCH proxmox-backup 2/2] manager: user: add 'user update-token' command Christoph Heiss
1 sibling, 0 replies; 3+ messages in thread
From: Christoph Heiss @ 2026-07-16 10:29 UTC (permalink / raw)
To: pbs-devel
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(¶m);
+
+ 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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH proxmox-backup 2/2] manager: user: add 'user update-token' command
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 ` [PATCH proxmox-backup 1/2] manager: user: make 'user generate-token' accept --output-format Christoph Heiss
@ 2026-07-16 10:29 ` Christoph Heiss
1 sibling, 0 replies; 3+ messages in thread
From: Christoph Heiss @ 2026-07-16 10:29 UTC (permalink / raw)
To: pbs-devel
.. enabling users to easily update API tokens from the command line.
Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
src/bin/proxmox_backup_manager/user.rs | 62 +++++++++++++++++++++++++-
1 file changed, 61 insertions(+), 1 deletion(-)
diff --git a/src/bin/proxmox_backup_manager/user.rs b/src/bin/proxmox_backup_manager/user.rs
index a429823de..93cb2d43f 100644
--- a/src/bin/proxmox_backup_manager/user.rs
+++ b/src/bin/proxmox_backup_manager/user.rs
@@ -6,7 +6,10 @@ use std::collections::HashMap;
use proxmox_router::{ApiHandler, RpcEnvironment, cli::*};
use proxmox_schema::api;
-use pbs_api_types::{ACL_PATH_SCHEMA, Authid, Tokenname, Userid};
+use pbs_api_types::{
+ ACL_PATH_SCHEMA, Authid, ENABLE_USER_SCHEMA, EXPIRE_USER_SCHEMA, REGENERATE_TOKEN_SCHEMA,
+ SINGLE_LINE_COMMENT_SCHEMA, Tokenname, Userid,
+};
use proxmox_backup::api2;
@@ -136,6 +139,56 @@ fn generate_token(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value
Ok(Value::Null)
}
+#[api(
+ input: {
+ properties: {
+ "output-format": {
+ schema: OUTPUT_FORMAT,
+ optional: true,
+ },
+ userid: {
+ type: Userid,
+ },
+ "token-name": {
+ type: Tokenname,
+ },
+ comment: {
+ optional: true,
+ schema: SINGLE_LINE_COMMENT_SCHEMA,
+ },
+ enable: {
+ schema: ENABLE_USER_SCHEMA,
+ optional: true,
+ },
+ expire: {
+ schema: EXPIRE_USER_SCHEMA,
+ optional: true,
+ },
+ regenerate: {
+ schema: REGENERATE_TOKEN_SCHEMA,
+ optional: true,
+ },
+ }
+ }
+)]
+/// Update an existing API token
+fn update_token(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
+ let output_format = get_output_format(¶m);
+
+ let info = &api2::access::user::API_METHOD_UPDATE_TOKEN;
+ let mut data = match info.handler {
+ ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
+ _ => unreachable!(),
+ };
+
+ let options = default_table_format_options().column(ColumnConfig::new("secret"));
+ if !data.is_null() {
+ format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
+ }
+
+ Ok(Value::Null)
+}
+
#[api(
input: {
properties: {
@@ -258,6 +311,13 @@ pub fn user_commands() -> CommandLineInterface {
.arg_param(&["userid", "token-name"])
.completion_cb("userid", pbs_config::user::complete_userid),
)
+ .insert(
+ "update-token",
+ CliCommand::new(&API_METHOD_UPDATE_TOKEN)
+ .arg_param(&["userid", "token-name"])
+ .completion_cb("userid", pbs_config::user::complete_userid)
+ .completion_cb("token-name", pbs_config::user::complete_token_name),
+ )
.insert(
"delete-token",
CliCommand::new(&api2::access::user::API_METHOD_DELETE_TOKEN)
--
2.54.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-07-16 10:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH proxmox-backup 1/2] manager: user: make 'user generate-token' accept --output-format Christoph Heiss
2026-07-16 10:29 ` [PATCH proxmox-backup 2/2] manager: user: add 'user update-token' command Christoph Heiss
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox