From 5eeea607aebb144a5e383413c4d683b35ed99ac1 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 30 Jan 2020 13:26:46 +0100 Subject: [PATCH] src/section_config.rs - convert_to_array: add option to skip properties --- src/api2/admin/datastore.rs | 4 ++-- src/api2/config/datastore.rs | 2 +- src/api2/config/remote.rs | 28 ++++++++++++++++++++++++++-- src/section_config.rs | 5 ++++- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index c95e1f52..40020a13 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -522,7 +522,7 @@ fn start_garbage_collection( } )] /// Garbage collection status. -fn garbage_collection_status( +pub fn garbage_collection_status( store: String, _info: &ApiMethod, _rpcenv: &mut dyn RpcEnvironment, @@ -544,7 +544,7 @@ fn get_datastore_list( let (config, _digest) = datastore::config()?; - Ok(config.convert_to_array("store", None)) + Ok(config.convert_to_array("store", None, &[])) } #[sortable] diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs index 4a737a3e..66ae9a5e 100644 --- a/src/api2/config/datastore.rs +++ b/src/api2/config/datastore.rs @@ -30,7 +30,7 @@ pub fn list_datastores( let (config, digest) = datastore::config()?; - Ok(config.convert_to_array("name", Some(&digest))) + Ok(config.convert_to_array("name", Some(&digest), &[])) } #[api( diff --git a/src/api2/config/remote.rs b/src/api2/config/remote.rs index ad9a5ae5..c5e2bb1a 100644 --- a/src/api2/config/remote.rs +++ b/src/api2/config/remote.rs @@ -14,7 +14,27 @@ use crate::config::remote; description: "The list of configured remotes (with config digest).", type: Array, items: { - type: remote::Remote, + type: Object, + description: "Remote configuration (without password).", + properties: { + name: { + schema: REMOTE_ID_SCHEMA, + }, + comment: { + optional: true, + schema: SINGLE_LINE_COMMENT_SCHEMA, + }, + host: { + schema: DNS_NAME_OR_IP_SCHEMA, + }, + userid: { + schema: PROXMOX_USER_ID_SCHEMA, + }, + fingerprint: { + optional: true, + schema: CERT_FINGERPRINT_SHA256_SCHEMA, + }, + }, }, }, )] @@ -27,7 +47,11 @@ pub fn list_remotes( let (config, digest) = remote::config()?; - Ok(config.convert_to_array("name", Some(&digest))) + let value = config.convert_to_array("name", Some(&digest), &["password"]); + + println!("TEST {:?}", value); + + Ok(value.into()) } #[api( diff --git a/src/section_config.rs b/src/section_config.rs index 49a613ef..ef7b6f41 100644 --- a/src/section_config.rs +++ b/src/section_config.rs @@ -85,7 +85,7 @@ impl SectionConfigData { self.order.push_back(section_id.to_string()); } - pub fn convert_to_array(&self, id_prop: &str, digest: Option<&[u8;32]>) -> Value { + pub fn convert_to_array(&self, id_prop: &str, digest: Option<&[u8;32]>, skip: &[&'static str]) -> Value { let mut list: Vec = vec![]; let digest: Value = match digest { @@ -95,6 +95,9 @@ impl SectionConfigData { for (section_id, (_, data)) in &self.sections { let mut item = data.clone(); + for prop in skip { + item.as_object_mut().unwrap().remove(*prop); + } item.as_object_mut().unwrap().insert(id_prop.into(), section_id.clone().into()); if !digest.is_null() { item.as_object_mut().unwrap().insert("digest".into(), digest.clone());