Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discoverabiltiy in kuksa.val.v1 API to enable e.g. Autocompletion #605

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
306dd27
Add discoverability feature to DataBroker
rafaeling Jul 4, 2023
67551e1
Regex for valid path request
rafaeling Jul 18, 2023
966ab61
Merge branch 'eclipse:master' into fb_add_discoverability_feature_to_…
rafaeling Jul 18, 2023
f346c78
Fix regex to accept correct use cases
rafaeling Jul 18, 2023
02082a7
Differentiate between leaf and branch according to VSS
rafaeling Jul 19, 2023
c85df9e
Merge branch 'eclipse:master' into fb_add_discoverability_feature_to_…
rafaeling Jul 20, 2023
c8a102d
Apply cargo fmt
rafaeling Jul 20, 2023
f786b8e
Fix unused import
rafaeling Jul 20, 2023
cc4bb94
Add Branch type to EntryType
rafaeling Jul 26, 2023
4d2c731
Error deleting spaces
rafaeling Jul 26, 2023
173c6b3
Error proto style
rafaeling Jul 26, 2023
9b7be38
Fix missing branch field
rafaeling Aug 1, 2023
8608557
Merge branch 'eclipse:master' into fb_add_discoverability_feature_to_…
rafaeling Aug 8, 2023
713d242
cargo format
rafaeling Aug 8, 2023
df7435e
clippy errors
rafaeling Aug 8, 2023
40e4c1b
No newline at end of file
rafaeling Aug 8, 2023
b8c7417
Pre-commit errors
rafaeling Aug 8, 2023
5d40304
Pre-commit errors 2
rafaeling Aug 8, 2023
3db4b7e
Merge branch 'eclipse:master' into fb_add_discoverability_feature_to_…
rafaeling Aug 11, 2023
27870f9
New autocompletion impl after desing discussions
rafaeling Aug 11, 2023
f124d51
Get rid of branches on broker
rafaeling Aug 15, 2023
3bbd8c9
Move regex path matching to glob
rafaeling Aug 17, 2023
873d413
Remove branch implementation
rafaeling Aug 17, 2023
79a41ee
Clean up branch implementation
rafaeling Aug 17, 2023
9d9cb65
Clean up branch proto
rafaeling Aug 17, 2023
aa56d51
Use glob regexes
rafaeling Aug 18, 2023
913a3fc
Reduce codelines
rafaeling Aug 18, 2023
effe593
Generalize regex and fix unit tests
rafaeling Aug 18, 2023
28c7ae3
Make regex more robust
rafaeling Aug 21, 2023
80aaf5a
Fix code
rafaeling Aug 21, 2023
808bd9b
fmt format
rafaeling Aug 21, 2023
aa3eace
fix regex
rafaeling Aug 21, 2023
38e7683
fix jobs
rafaeling Aug 21, 2023
e4d260f
Use generic regex and improve implementation
rafaeling Aug 22, 2023
518c347
Remove unused code
rafaeling Aug 22, 2023
8971f7a
Adapt regex and unit tests
rafaeling Aug 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions kuksa_databroker/databroker/src/glob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use regex::Regex;

#[derive(Debug)]
pub enum Error {
RegexError,
}
Expand Down Expand Up @@ -51,3 +52,64 @@ pub fn to_regex(glob: &str) -> Result<Regex, Error> {
let re = to_regex_string(glob);
Regex::new(&re).map_err(|_err| Error::RegexError)
}

pub fn matches_path_pattern(input: &str) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn matches_path_pattern(input: &str) -> bool {
pub fn is_valid_pattern(input: &str) -> bool {

if !input.starts_with('*') {
let pattern = r"^(?:\w+(?:\.\w+)*)(?:\.\*+)?$";
let regex = Regex::new(pattern).unwrap();

let pattern2 = r"^[^.]+(\.[^.]+)*\.(\*{2}|\*|[A-Za-z]+)(\.[^.]+)*\.[^.]+$";
let regex2 = Regex::new(pattern2).unwrap();

regex.is_match(input) || regex2.is_match(input)
} else {
false
}
}

#[tokio::test]
async fn test_valid_request_path() {
let inputs = vec![
argerus marked this conversation as resolved.
Show resolved Hide resolved
"String.*",
"String.**",
"String.String.String.String.*",
"String.String.String.String.**",
"String.String.String.String",
"String.String.String.String.String.**",
"String.String.String.*.String",
"String.String.String.**.String",
"String.String.String.String.String.**.String",
"String.String.String.String.*.String.String",
"String.*.String.String",
"String.String.**.String.String",
"String.**.String.String",
"String.String.String.",
"String.String.String.String..",
"String.*.String.String..",
"*.String.String.String..",
"*.String.String.String",
"**.String.String.String.**",
"**.String.String.String.*",
];

assert!(matches_path_pattern(inputs[0]));
assert!(matches_path_pattern(inputs[1]));
assert!(matches_path_pattern(inputs[2]));
assert!(matches_path_pattern(inputs[3]));
assert!(matches_path_pattern(inputs[4]));
assert!(matches_path_pattern(inputs[5]));
assert!(matches_path_pattern(inputs[6]));
assert!(matches_path_pattern(inputs[7]));
assert!(matches_path_pattern(inputs[8]));
assert!(matches_path_pattern(inputs[9]));
assert!(matches_path_pattern(inputs[10]));
assert!(matches_path_pattern(inputs[11]));
assert!(matches_path_pattern(inputs[12]));
assert!(!matches_path_pattern(inputs[13]));
assert!(!matches_path_pattern(inputs[14]));
assert!(!matches_path_pattern(inputs[15]));
assert!(!matches_path_pattern(inputs[16]));
assert!(!matches_path_pattern(inputs[17]));
assert!(!matches_path_pattern(inputs[18]));
argerus marked this conversation as resolved.
Show resolved Hide resolved
assert!(!matches_path_pattern(inputs[19]));
}
37 changes: 2 additions & 35 deletions kuksa_databroker/databroker/src/grpc/kuksa_val_v1/val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

use regex::Regex;
use std::collections::HashMap;
use std::collections::HashSet;
use std::iter::FromIterator;
Expand All @@ -27,6 +26,7 @@ use crate::broker;
use crate::broker::ReadError;
use crate::broker::SubscriptionError;
use crate::permissions::Permissions;
use crate::glob;

#[tonic::async_trait]
impl proto::val_server::Val for broker::DataBroker {
Expand Down Expand Up @@ -55,7 +55,7 @@ impl proto::val_server::Val for broker::DataBroker {
let mut errors = Vec::new();

for request in requested {
match matches_path_pattern(&request.path) {
match glob::matches_path_pattern(&request.path) {
true => {
match broker.get_entry_by_path(&request.path).await {
Ok(entry) => {
Expand Down Expand Up @@ -749,12 +749,6 @@ fn combine_view_and_fields(
combined
}

fn matches_path_pattern(input: &str) -> bool {
let pattern = r"^(?:\w+(?:\.\w+)*)(?:\.\*+)?$";
let regex = Regex::new(pattern).unwrap();
regex.is_match(input)
}

impl broker::EntryUpdate {
fn from_proto_entry_and_fields(
entry: &proto::DataEntry,
Expand Down Expand Up @@ -846,31 +840,4 @@ mod tests {
Err(_status) => panic!("failed to execute set request"),
}
}

#[tokio::test]
async fn test_valid_request_path() {
let inputs = vec![
"String.*",
"String.**",
"String.String.String.String.*",
"String.String.String.String.**",
"String.String.String.String",
"String.String.String.String.String.**",
"String.String.String.",
"String.String.String.String..",
"String.*.String.String..",
"*.String.String.String..",
];

assert!(matches_path_pattern(inputs[0]));
assert!(matches_path_pattern(inputs[1]));
assert!(matches_path_pattern(inputs[2]));
assert!(matches_path_pattern(inputs[3]));
assert!(matches_path_pattern(inputs[4]));
assert!(matches_path_pattern(inputs[5]));
assert!(!matches_path_pattern(inputs[6]));
assert!(!matches_path_pattern(inputs[7]));
assert!(!matches_path_pattern(inputs[8]));
assert!(!matches_path_pattern(inputs[9]));
}
}
Loading