archivist_config/
archivist-config_rust_config_lib_source.rs

1use fidl::unpersist;
2use fidl_cf_sc_internal_archivistconfig::Config as FidlConfig;
3use fuchsia_component_config::{Config as ComponentConfig, Error};
4use fuchsia_inspect::{ArrayProperty, Node};
5use std::convert::TryInto;
6const EXPECTED_CHECKSUM: &[u8] = &[
7    0xad, 0x2d, 0xa7, 0x3c, 0x98, 0x65, 0x93, 0x64, 0x02, 0xd1, 0x39, 0x15, 0xc7, 0x21, 0xaf, 0xe3,
8    0x63, 0xcd, 0x55, 0xb3, 0xcf, 0x36, 0x33, 0x1f, 0x99, 0xcf, 0x24, 0x43, 0x9f, 0x16, 0xe9, 0xf9,
9];
10#[derive(Debug)]
11pub struct Config {
12    pub allow_serial_logs: Vec<String>,
13    pub bind_services: Vec<String>,
14    pub component_initial_interests: Vec<String>,
15    pub deny_serial_log_tags: Vec<String>,
16    pub enable_klog: bool,
17    pub log_to_debuglog: bool,
18    pub logs_max_cached_original_bytes: u64,
19    pub maximum_concurrent_snapshots_per_reader: u64,
20    pub num_threads: u8,
21    pub per_component_batch_timeout_seconds: i64,
22    pub pipelines_path: String,
23}
24impl Config {
25    #[doc = r" Take the config startup handle and parse its contents."]
26    #[doc = r""]
27    #[doc = r" # Panics"]
28    #[doc = r""]
29    #[doc = r" If the config startup handle was already taken or if it is not valid."]
30    pub fn take_from_startup_handle() -> Self {
31        <Self as ComponentConfig>::take_from_startup_handle()
32    }
33    #[doc = r" Parse `Self` from `vmo`."]
34    pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
35        <Self as ComponentConfig>::from_vmo(vmo)
36    }
37    #[doc = r" Parse `Self` from `bytes`."]
38    pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
39        <Self as ComponentConfig>::from_bytes(bytes)
40    }
41    pub fn record_inspect(&self, inspector_node: &Node) {
42        <Self as ComponentConfig>::record_inspect(self, inspector_node)
43    }
44}
45impl ComponentConfig for Config {
46    #[doc = r" Parse `Self` from `bytes`."]
47    fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
48        let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
49        let checksum_len_bytes: [u8; 2] =
50            checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
51        let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
52        let (observed_checksum, bytes) =
53            bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
54        if observed_checksum != EXPECTED_CHECKSUM {
55            return Err(Error::ChecksumMismatch {
56                expected_checksum: EXPECTED_CHECKSUM.to_vec(),
57                observed_checksum: observed_checksum.to_vec(),
58            });
59        }
60        let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
61        Ok(Self {
62            allow_serial_logs: fidl_config.allow_serial_logs,
63            bind_services: fidl_config.bind_services,
64            component_initial_interests: fidl_config.component_initial_interests,
65            deny_serial_log_tags: fidl_config.deny_serial_log_tags,
66            enable_klog: fidl_config.enable_klog,
67            log_to_debuglog: fidl_config.log_to_debuglog,
68            logs_max_cached_original_bytes: fidl_config.logs_max_cached_original_bytes,
69            maximum_concurrent_snapshots_per_reader: fidl_config
70                .maximum_concurrent_snapshots_per_reader,
71            num_threads: fidl_config.num_threads,
72            per_component_batch_timeout_seconds: fidl_config.per_component_batch_timeout_seconds,
73            pipelines_path: fidl_config.pipelines_path,
74        })
75    }
76    fn record_inspect(&self, inspector_node: &Node) {
77        let arr =
78            inspector_node.create_string_array("allow_serial_logs", self.allow_serial_logs.len());
79        for i in 0..self.allow_serial_logs.len() {
80            arr.set(i, &self.allow_serial_logs[i]);
81        }
82        inspector_node.record(arr);
83        let arr = inspector_node.create_string_array("bind_services", self.bind_services.len());
84        for i in 0..self.bind_services.len() {
85            arr.set(i, &self.bind_services[i]);
86        }
87        inspector_node.record(arr);
88        let arr = inspector_node.create_string_array(
89            "component_initial_interests",
90            self.component_initial_interests.len(),
91        );
92        for i in 0..self.component_initial_interests.len() {
93            arr.set(i, &self.component_initial_interests[i]);
94        }
95        inspector_node.record(arr);
96        let arr = inspector_node
97            .create_string_array("deny_serial_log_tags", self.deny_serial_log_tags.len());
98        for i in 0..self.deny_serial_log_tags.len() {
99            arr.set(i, &self.deny_serial_log_tags[i]);
100        }
101        inspector_node.record(arr);
102        inspector_node.record_bool("enable_klog", self.enable_klog);
103        inspector_node.record_bool("log_to_debuglog", self.log_to_debuglog);
104        inspector_node
105            .record_uint("logs_max_cached_original_bytes", self.logs_max_cached_original_bytes);
106        inspector_node.record_uint(
107            "maximum_concurrent_snapshots_per_reader",
108            self.maximum_concurrent_snapshots_per_reader,
109        );
110        inspector_node.record_uint("num_threads", self.num_threads as u64);
111        inspector_node.record_int(
112            "per_component_batch_timeout_seconds",
113            self.per_component_batch_timeout_seconds,
114        );
115        inspector_node.record_string("pipelines_path", &self.pipelines_path);
116    }
117}