src/section_config.rs - convert_to_array: add option to skip properties
This commit is contained in:
		@ -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]
 | 
			
		||||
 | 
			
		||||
@ -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(
 | 
			
		||||
 | 
			
		||||
@ -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(
 | 
			
		||||
 | 
			
		||||
@ -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<Value> = 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());
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user