[pbs-devel] [PATCH proxmox-backup 2/5] api2: add missing token list match_all property
Dominik Csapak
d.csapak at proxmox.com
Thu Sep 9 15:48:16 CEST 2021
to have the proper link between the token list and the sub routes
in the api, include the 'tokenname' property in the token listing
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
src/api2/access/user.rs | 35 ++++++++++++++++++++++++++++-------
1 file changed, 28 insertions(+), 7 deletions(-)
diff --git a/src/api2/access/user.rs b/src/api2/access/user.rs
index 6a2fe83c..70065986 100644
--- a/src/api2/access/user.rs
+++ b/src/api2/access/user.rs
@@ -655,6 +655,21 @@ pub fn delete_token(
Ok(())
}
+#[api(
+ properties: {
+ tokenname: { type: Tokenname },
+ token: { type: ApiToken },
+ }
+)]
+#[derive(Serialize, Deserialize)]
+/// A Token Entry of a user
+pub struct TokenInfo {
+ /// The Token name
+ pub tokenname: Tokenname,
+ #[serde(flatten)]
+ pub token: ApiToken,
+}
+
#[api(
input: {
properties: {
@@ -666,7 +681,7 @@ pub fn delete_token(
returns: {
description: "List user's API tokens (with config digest).",
type: Array,
- items: { type: ApiToken },
+ items: { type: TokenInfo },
},
access: {
permission: &Permission::Or(&[
@@ -680,7 +695,7 @@ pub fn list_tokens(
userid: Userid,
_info: &ApiMethod,
mut rpcenv: &mut dyn RpcEnvironment,
-) -> Result<Vec<ApiToken>, Error> {
+) -> Result<Vec<TokenInfo>, Error> {
let (config, digest) = crate::config::user::config()?;
@@ -688,15 +703,21 @@ pub fn list_tokens(
rpcenv["digest"] = proxmox::tools::digest_to_hex(&digest).into();
- let filter_by_owner = |token: &ApiToken| {
- if token.tokenid.is_token() {
- token.tokenid.user() == &userid
+ let filter_by_owner = |token: ApiToken| {
+ if token.tokenid.is_token() && token.tokenid.user() == &userid {
+ let tokenname = token.tokenid.tokenname().unwrap().to_owned();
+ Some(TokenInfo {
+ tokenname,
+ token,
+ })
} else {
- false
+ None
}
};
- Ok(list.into_iter().filter(filter_by_owner).collect())
+ let res = list.into_iter().filter_map(filter_by_owner).collect();
+
+ Ok(res)
}
const TOKEN_ITEM_ROUTER: Router = Router::new()
--
2.30.2
More information about the pbs-devel
mailing list