Skip to content

Commit

Permalink
fixup! feat: Query parameter support for entity store query API
Browse files Browse the repository at this point in the history
  • Loading branch information
albinsuresh committed Feb 6, 2025
1 parent c30dccf commit 1bd4b22
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
2 changes: 1 addition & 1 deletion crates/core/tedge_agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repository = { workspace = true }
[dependencies]
anyhow = { workspace = true }
async-trait = { workspace = true }
axum = { workspace = true }
axum = { workspace = true, features = ["macros"] }
axum-server = { workspace = true }
axum_tls = { workspace = true }
camino = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/core/tedge_agent/src/http_server/entity_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ mod tests {
let response = app.call(req).await.unwrap();
assert_eq!(response.status(), StatusCode::OK);

let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let body = response.into_body().collect().await.unwrap().to_bytes();
let entities: Vec<EntityMetadata> = serde_json::from_slice(&body).unwrap();

let entity_set = entities
Expand Down
43 changes: 31 additions & 12 deletions crates/core/tedge_api/src/entity_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,20 +710,26 @@ impl EntityTree {
let mut entities = vec![];

while let Some(topic_id) = topic_ids.pop_front() {
let metadata = self.entities.get(topic_id).map(|node| node.metadata()).unwrap();
let metadata = self
.entities
.get(topic_id)
.map(|node| node.metadata())
.unwrap();
if filters.matches(metadata) {
entities.push(metadata);
}

let (child_topics, _): (Vec<_>, Vec<_>) = self
.children(topic_id)
.into_iter()
.unzip();
let (child_topics, _): (Vec<_>, Vec<_>) =
self.children(topic_id).into_iter().unzip();

// If the `parent` filter is used, no need to search beyond the direct children of that parent
if filters.parent.as_ref().map_or(true, |parent| parent == topic_id) {
if filters
.parent
.as_ref()
.map_or(true, |parent| parent == topic_id)
{
topic_ids.extend(child_topics);
}
}
}
Ok(entities)
} else {
Expand Down Expand Up @@ -992,7 +998,8 @@ mod tests {
use assert_matches::assert_matches;
use mqtt_channel::Topic;
use serde_json::json;
use std::{collections::BTreeSet, str::FromStr};
use std::collections::BTreeSet;
use std::str::FromStr;
use tempfile::TempDir;
use test_case::test_case;

Expand Down Expand Up @@ -1102,7 +1109,7 @@ mod tests {
}

#[test_case(
ListFilters::default(),
ListFilters::default(),
BTreeSet::from([
"device/main//",
"device/main/service/service0",
Expand Down Expand Up @@ -1265,10 +1272,22 @@ mod tests {
Some("device/child00//"),
),
("device/child1//", "child-device", None),
("device/child1/service/service10", "service", Some("device/child1//")),
(
"device/child1/service/service10",
"service",
Some("device/child1//"),
),
("device/child2//", "child-device", None),
("device/child2/service/service20", "service", Some("device/child2//")),
("device/child2/service/service21", "service", Some("device/child2//")),
(
"device/child2/service/service20",
"service",
Some("device/child2//"),
),
(
"device/child2/service/service21",
"service",
Some("device/child2//"),
),
("device/child20//", "child-device", Some("device/child2//")),
("device/child21//", "child-device", Some("device/child2//")),
(
Expand Down
2 changes: 1 addition & 1 deletion tests/RobotFramework/libraries/ThinEdgeIO/ThinEdgeIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ def list_entities(
query_string = "&".join(f"{key}={value}" for key, value in params.items())
url += f"?{query_string}"

output = device.execute_command(f"curl -f {url}")
output = device.execute_command(f"curl -f '{url}'")
entities = json.loads(output.stdout)
return entities

Expand Down

0 comments on commit 1bd4b22

Please sign in to comment.