Skip to content

Commit

Permalink
Test glob matching library
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaeling committed May 13, 2024
1 parent c7950be commit 010fa74
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions databroker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
jsonwebtoken = "9.1.0"
regex = "1.7.1"
glob-match = "0.2.1"

jemallocator = { version = "0.5.0", optional = true }
lazy_static = "1.4.0"
Expand Down
26 changes: 7 additions & 19 deletions databroker/src/grpc/kuksa_val_v1/val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use databroker_proto::kuksa::val::v1::DataEntryError;
use tokio_stream::Stream;
use tokio_stream::StreamExt;
use tracing::debug;
use glob_match::glob_match;

use crate::broker;
use crate::broker::EntryReadAccess;
Expand Down Expand Up @@ -63,7 +64,7 @@ impl proto::val_server::Val for broker::DataBroker {
* - Error: An optional ReadError representing a permission error that may occur when querying a valid path entry.
*/
let mut valid_requests: Vec<(
regex::Regex,
String,
HashSet<proto::Field>,
String,
bool,
Expand Down Expand Up @@ -93,30 +94,17 @@ impl proto::val_server::Val for broker::DataBroker {
let view_fields = combine_view_and_fields(view, fields);
debug!("Getting fields: {:?}", view_fields);

let regex_exp = glob::to_regex(&request.path);
match regex_exp {
Ok(value) => {
valid_requests.push((value, view_fields, request.path, false, None));
}
Err(_) => {
errors.push(proto::DataEntryError {
path: request.path,
error: Some(proto::Error {
code: 400,
reason: "bad regex".to_owned(),
message: "Regex can't be created for provided path".to_owned(),
}),
});
}
}
let glob_string = glob::to_regex_string(&request.path);

valid_requests.push((glob_string, view_fields, request.path, false, None));
}
if !valid_requests.is_empty() {
broker
.for_each_entry(|entry| {
let mut result_fields: HashSet<proto::Field> = HashSet::new();
for (regex, view_fields, _, is_match, op_error) in &mut valid_requests {
for (glob, view_fields, _, is_match, op_error) in &mut valid_requests {
let path = &entry.metadata().path;
if regex.is_match(path) {
if glob_match(glob, path) {
// Update the `is_match` to indicate a valid and used request path.
*is_match = true;
if view_fields.contains(&proto::Field::Metadata) {
Expand Down

0 comments on commit 010fa74

Please sign in to comment.