gent_daemon/config/
hosted.rs1use super::*;
3
4#[derive(Clone, Debug, Serialize, Deserialize)]
5#[serde(deny_unknown_fields)]
6pub struct HostedParent {
7 pub home: PathBuf,
8 pub node_id: String,
9}
10
11impl Config {
12 pub fn hosted_parent(&self) -> Result<Option<HostedParent>> {
13 self.extra
14 .get("hosted_parent")
15 .cloned()
16 .map(|value| {
17 let parent: HostedParent = value.try_into().context("invalid hosted parent")?;
18 let node = uuid::Uuid::parse_str(&parent.node_id)?;
19 ensure!(
20 parent.home.is_absolute()
21 && !node.is_nil()
22 && node.to_string() == parent.node_id
23 && parent.node_id != self.node.id,
24 "invalid hosted parent identity or path"
25 );
26 Ok(parent)
27 })
28 .transpose()
29 }
30
31 pub fn set_hosted_parent(&mut self, parent: HostedParent) -> Result<()> {
32 self.extra
33 .insert("hosted_parent".into(), toml::Value::try_from(parent)?);
34 self.update_local_version()?;
35 self.hosted_parent()?;
36 Ok(())
37 }
38}