Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0eb513b2 authored by Ted Bauer's avatar Ted Bauer Committed by Gerrit Code Review
Browse files

Merge "Show containers in list new storage" into main

parents e1e07f89 83d2a58d
Loading
Loading
Loading
Loading
+22 −6
Original line number Diff line number Diff line
use crate::load_protos;
use crate::{Flag, FlagSource};
use crate::{FlagPermission, FlagValue, ValuePickedFrom};
use aconfigd_protos::{
@@ -9,13 +10,18 @@ use anyhow::anyhow;
use anyhow::Result;
use protobuf::Message;
use protobuf::SpecialFields;
use std::collections::HashMap;
use std::io::{Read, Write};
use std::net::Shutdown;
use std::os::unix::net::UnixStream;

pub struct AconfigStorageSource {}

fn convert(msg: ProtoFlagQueryReturnMessage) -> Result<Flag> {
fn load_flag_to_container() -> Result<HashMap<String, String>> {
    Ok(load_protos::load()?.into_iter().map(|p| (p.qualified_name(), p.container)).collect())
}

fn convert(msg: ProtoFlagQueryReturnMessage, containers: &HashMap<String, String>) -> Result<Flag> {
    let (value, value_picked_from) = match (
        &msg.boot_flag_value,
        msg.default_flag_value,
@@ -55,15 +61,21 @@ fn convert(msg: ProtoFlagQueryReturnMessage) -> Result<Flag> {
        None => return Err(anyhow!("missing permission")),
    };

    let name = msg.flag_name.ok_or(anyhow!("missing flag name"))?;
    let package = msg.package_name.ok_or(anyhow!("missing package name"))?;
    let qualified_name = format!("{package}.{name}");
    Ok(Flag {
        name: msg.flag_name.ok_or(anyhow!("missing flag name"))?,
        package: msg.package_name.ok_or(anyhow!("missing package name"))?,
        name,
        package,
        value,
        permission,
        value_picked_from,
        staged_value,
        container: "-".to_string(),

        container: containers
            .get(&qualified_name)
            .cloned()
            .unwrap_or_else(|| "<no container>".to_string())
            .to_string(),
        // TODO: remove once DeviceConfig is not in the CLI.
        namespace: "-".to_string(),
    })
@@ -114,9 +126,13 @@ fn read_from_socket() -> Result<Vec<ProtoFlagQueryReturnMessage>> {

impl FlagSource for AconfigStorageSource {
    fn list_flags() -> Result<Vec<Flag>> {
        let containers = load_flag_to_container()?;
        read_from_socket()
            .map(|query_messages| {
                query_messages.iter().map(|message| convert(message.clone())).collect::<Vec<_>>()
                query_messages
                    .iter()
                    .map(|message| convert(message.clone(), &containers))
                    .collect::<Vec<_>>()
            })?
            .into_iter()
            .collect()