src/section_config.rs - convert_to_array: add option to skip properties

This commit is contained in:
Dietmar Maurer 2020-01-30 13:26:46 +01:00
parent 3f0983b7a3
commit 5eeea607ae
4 changed files with 33 additions and 6 deletions

View File

@ -522,7 +522,7 @@ fn start_garbage_collection(
} }
)] )]
/// Garbage collection status. /// Garbage collection status.
fn garbage_collection_status( pub fn garbage_collection_status(
store: String, store: String,
_info: &ApiMethod, _info: &ApiMethod,
_rpcenv: &mut dyn RpcEnvironment, _rpcenv: &mut dyn RpcEnvironment,
@ -544,7 +544,7 @@ fn get_datastore_list(
let (config, _digest) = datastore::config()?; let (config, _digest) = datastore::config()?;
Ok(config.convert_to_array("store", None)) Ok(config.convert_to_array("store", None, &[]))
} }
#[sortable] #[sortable]

View File

@ -30,7 +30,7 @@ pub fn list_datastores(
let (config, digest) = datastore::config()?; let (config, digest) = datastore::config()?;
Ok(config.convert_to_array("name", Some(&digest))) Ok(config.convert_to_array("name", Some(&digest), &[]))
} }
#[api( #[api(

View File

@ -14,7 +14,27 @@ use crate::config::remote;
description: "The list of configured remotes (with config digest).", description: "The list of configured remotes (with config digest).",
type: Array, type: Array,
items: { 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()?; 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( #[api(

View File

@ -85,7 +85,7 @@ impl SectionConfigData {
self.order.push_back(section_id.to_string()); 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<Value> = vec![]; let mut list: Vec<Value> = vec![];
let digest: Value = match digest { let digest: Value = match digest {
@ -95,6 +95,9 @@ impl SectionConfigData {
for (section_id, (_, data)) in &self.sections { for (section_id, (_, data)) in &self.sections {
let mut item = data.clone(); 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()); item.as_object_mut().unwrap().insert(id_prop.into(), section_id.clone().into());
if !digest.is_null() { if !digest.is_null() {
item.as_object_mut().unwrap().insert("digest".into(), digest.clone()); item.as_object_mut().unwrap().insert("digest".into(), digest.clone());