Show containers in list new storage
Test: m Bug: 324436145 Change-Id: I695aa130aee356451aa8196911d31b87d45d745d
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::load_protos;
|
||||||
use crate::{Flag, FlagSource};
|
use crate::{Flag, FlagSource};
|
||||||
use crate::{FlagPermission, FlagValue, ValuePickedFrom};
|
use crate::{FlagPermission, FlagValue, ValuePickedFrom};
|
||||||
use aconfigd_protos::{
|
use aconfigd_protos::{
|
||||||
@@ -9,13 +10,18 @@ use anyhow::anyhow;
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use protobuf::Message;
|
use protobuf::Message;
|
||||||
use protobuf::SpecialFields;
|
use protobuf::SpecialFields;
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::net::Shutdown;
|
use std::net::Shutdown;
|
||||||
use std::os::unix::net::UnixStream;
|
use std::os::unix::net::UnixStream;
|
||||||
|
|
||||||
pub struct AconfigStorageSource {}
|
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 (
|
let (value, value_picked_from) = match (
|
||||||
&msg.boot_flag_value,
|
&msg.boot_flag_value,
|
||||||
msg.default_flag_value,
|
msg.default_flag_value,
|
||||||
@@ -55,15 +61,21 @@ fn convert(msg: ProtoFlagQueryReturnMessage) -> Result<Flag> {
|
|||||||
None => return Err(anyhow!("missing permission")),
|
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 {
|
Ok(Flag {
|
||||||
name: msg.flag_name.ok_or(anyhow!("missing flag name"))?,
|
name,
|
||||||
package: msg.package_name.ok_or(anyhow!("missing package name"))?,
|
package,
|
||||||
value,
|
value,
|
||||||
permission,
|
permission,
|
||||||
value_picked_from,
|
value_picked_from,
|
||||||
staged_value,
|
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.
|
// TODO: remove once DeviceConfig is not in the CLI.
|
||||||
namespace: "-".to_string(),
|
namespace: "-".to_string(),
|
||||||
})
|
})
|
||||||
@@ -114,9 +126,13 @@ fn read_from_socket() -> Result<Vec<ProtoFlagQueryReturnMessage>> {
|
|||||||
|
|
||||||
impl FlagSource for AconfigStorageSource {
|
impl FlagSource for AconfigStorageSource {
|
||||||
fn list_flags() -> Result<Vec<Flag>> {
|
fn list_flags() -> Result<Vec<Flag>> {
|
||||||
|
let containers = load_flag_to_container()?;
|
||||||
read_from_socket()
|
read_from_socket()
|
||||||
.map(|query_messages| {
|
.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()
|
.into_iter()
|
||||||
.collect()
|
.collect()
|
||||||
|
Reference in New Issue
Block a user