1
0
mirror of https://github.com/aziascreations/BakaShrot.git synced 2026-11-23 20:58:46 +01:00

Added the list_topics and list_nodes role flags, Filtered the nodes listed by the roles

- `list_topics` / `list_nodes`: listing answers every topic, every node
  with messages, without reading any (`query` gives both).
- Without them, listing nodes only answers those with messages in the
  topics the roles may read (every node until now).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 01:40:01 +01:00
parent cf8264b21d
commit c86dc8798e
14 changed files with 122 additions and 31 deletions
+4
View File
@@ -56,6 +56,10 @@ push_topics = ["sensors.*"] # always as its own node (its name)
[roles.dashboard]
read_topics = ["*"]
query = true # read-only SQL, reads every topic
# Listing answers the topics it may push to or read, and the nodes of the
# topics it may read. These answer every one (query does too):
# list_topics = true
# list_nodes = true
# Peers are roles too: what's replicated with a server whose certificate
# has this role, whichever end dials.
+19
View File
@@ -61,6 +61,14 @@ pub struct Role {
/// Whether it may run read-only SQL, which reads every topic.
#[serde(default)]
pub query: bool,
/// Whether listing topics answers every topic with messages, not only
/// those it may push to or read.
#[serde(default)]
pub list_topics: bool,
/// Whether listing nodes answers every node with messages, not only
/// those of the topics it may read.
#[serde(default)]
pub list_nodes: bool,
/// Replication: the topics sent to it.
#[serde(default)]
pub send_topics: NameList,
@@ -109,6 +117,17 @@ impl Permissions {
self.roles.iter().any(|role| role.query)
}
/// Whether listing topics answers every one: `list_topics`, or
/// `query` (which reads them all anyway).
pub fn lists_every_topic(&self) -> bool {
self.roles.iter().any(|role| role.list_topics || role.query)
}
/// Whether listing nodes answers every one: `list_nodes`, or `query`.
pub fn lists_every_node(&self) -> bool {
self.roles.iter().any(|role| role.list_nodes || role.query)
}
/// Whether `node`'s messages in `topic` are sent to it.
pub fn sends(&self, topic: &str, node: &str) -> bool {
self.roles
+13 -1
View File
@@ -164,7 +164,19 @@ accept_nodes = ["garage"]
assert!(both.can_read("Logs"));
assert!(!both.can_read("sensors.garage"));
assert!(!both.can_query());
assert!(config.permissions(&["admin"]).unwrap().can_query());
assert!(!both.lists_every_topic() && !both.lists_every_node());
let admin = config.permissions(&["admin"]).unwrap();
assert!(admin.can_query());
// A query reads them all anyway.
assert!(admin.lists_every_topic() && admin.lists_every_node());
let listing = Config::parse(&with(
"[roles.a]\nlist_topics = true\n[roles.b]\nlist_nodes = true\n",
))
.unwrap();
let a = listing.permissions(&["a"]).unwrap();
assert!(a.lists_every_topic() && !a.lists_every_node() && !a.can_query());
let b = listing.permissions(&["b", "a"]).unwrap();
assert!(b.lists_every_topic() && b.lists_every_node());
// Replication: each role's topics with that role's nodes, not mixed.
let peer = config.permissions(&["peer", "backup"]).unwrap();