Watch
0
0
Fork
You've already forked hyperhive
0

swarm: unrestricted_internet flag on the agent permissions record, unset reads as on, create writes false

This commit is contained in:
atlas 2026-10-27 11:29:06 +01:00 • committed by mara
commit 8699857024

View file

@ -71,6 +71,12 @@ pub const IMPORT_REPLY_DEADLINE: std::time::Duration = std::time::Duration::from
pub struct AgentPermissions {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub permissions: Option<Vec<hive_types::Permission>>,
/// Whether the agent's traffic leaves the host unfiltered. Absent is "on":
/// an agent whose key predates the field keeps the open access it had, and
/// the controller writes an explicit `false` when it creates an agent. Read
/// it through `swarm_queue_client::agent_permissions::unrestricted`.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub unrestricted_internet: Option<bool>,
}
/// What a hive sends once: the permissions its meta repo held, by agent.
@ -140,4 +146,19 @@ mod tests {
serde_json::from_str(r#"{"permissions":["manage_root_agent"]}"#).unwrap();
assert_eq!(ruth.permissions, Some(vec![Permission::ManageRootAgent]));
}
/// The flag is left out when unset, so a record that never named it
/// encodes as before, and an explicit `false` is kept on the wire.
#[test]
fn the_internet_flag_is_left_out_unless_set() {
let off = AgentPermissions {
unrestricted_internet: Some(false),
..AgentPermissions::default()
};
let wire = r#"{"unrestricted_internet":false}"#;
assert_eq!(serde_json::to_string(&off).unwrap(), wire);
assert_eq!(serde_json::from_str::<AgentPermissions>(wire).unwrap(), off);
let unset: AgentPermissions = serde_json::from_str("{}").unwrap();
assert_eq!(unset.unrestricted_internet, None);
}
}