From 24cb5c7a81a25eb2ff291191864bf05d61028af0 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 20 Apr 2022 09:40:05 +0200 Subject: [PATCH] RemoteWithoutPassword: new API type To make it explicit that we do not return the password. Signed-off-by: Dietmar Maurer --- pbs-api-types/src/remote.rs | 19 +++++++++++++++++++ src/api2/config/remote.rs | 15 ++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/pbs-api-types/src/remote.rs b/pbs-api-types/src/remote.rs index 1ebc9d4c..890e31c0 100644 --- a/pbs-api-types/src/remote.rs +++ b/pbs-api-types/src/remote.rs @@ -85,3 +85,22 @@ pub struct Remote { #[serde(flatten)] pub config: RemoteConfig, } + +#[api( + properties: { + name: { + schema: REMOTE_ID_SCHEMA, + }, + config: { + type: RemoteConfig, + }, + }, +)] +#[derive(Serialize, Deserialize)] +#[serde(rename_all = "kebab-case")] +/// Remote properties. +pub struct RemoteWithoutPassword { + pub name: String, + #[serde(flatten)] + pub config: RemoteConfig, +} diff --git a/src/api2/config/remote.rs b/src/api2/config/remote.rs index 8b41c12f..3fcc650a 100644 --- a/src/api2/config/remote.rs +++ b/src/api2/config/remote.rs @@ -11,8 +11,8 @@ use proxmox_schema::{api, param_bail}; use pbs_api_types::{ Authid, DataStoreListItem, GroupListItem, RateLimitConfig, Remote, RemoteConfig, - RemoteConfigUpdater, SyncJobConfig, DATASTORE_SCHEMA, PRIV_REMOTE_AUDIT, PRIV_REMOTE_MODIFY, - PROXMOX_CONFIG_DIGEST_SCHEMA, REMOTE_ID_SCHEMA, REMOTE_PASSWORD_SCHEMA, + RemoteConfigUpdater, RemoteWithoutPassword, SyncJobConfig, DATASTORE_SCHEMA, PRIV_REMOTE_AUDIT, + PRIV_REMOTE_MODIFY, PROXMOX_CONFIG_DIGEST_SCHEMA, REMOTE_ID_SCHEMA, REMOTE_PASSWORD_SCHEMA, }; use pbs_client::{HttpClient, HttpClientOptions}; use pbs_config::sync; @@ -26,7 +26,7 @@ use pbs_config::CachedUserInfo; returns: { description: "The list of configured remotes (with config digest).", type: Array, - items: { type: Remote }, + items: { type: RemoteWithoutPassword }, }, access: { description: "List configured remotes filtered by Remote.Audit privileges", @@ -38,17 +38,14 @@ pub fn list_remotes( _param: Value, _info: &ApiMethod, mut rpcenv: &mut dyn RpcEnvironment, -) -> Result, Error> { +) -> Result, Error> { let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; let user_info = CachedUserInfo::new()?; let (config, digest) = pbs_config::remote::config()?; - let mut list: Vec = config.convert_to_typed_array("remote")?; - // don't return password in api - for remote in &mut list { - remote.password = "".to_string(); - } + // Note: This removes the password (we do not want to return the password). + let list: Vec = config.convert_to_typed_array("remote")?; let list = list .into_iter()