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

Resolve clippy errors after Rust update #915

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
63 changes: 26 additions & 37 deletions src/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
where
T: EventFilter + DeserializeOwned,
{
let (start, end) = time_range(&filter.time);
let (start, end) = time_range(filter.time.as_ref());
let search_time = target_data
.iter()
.filter_map(|(time, value)| {
Expand Down Expand Up @@ -224,7 +224,7 @@
search_time
}

fn time_range(time_range: &Option<TimeRange>) -> (DateTime<Utc>, DateTime<Utc>) {
fn time_range(time_range: Option<&TimeRange>) -> (DateTime<Utc>, DateTime<Utc>) {
let (start, end) = if let Some(time) = time_range {
(time.start, time.end)
} else {
Expand Down Expand Up @@ -448,8 +448,8 @@
fn get_peekable_iter<'c, T>(
store: &RawEventStore<'c, T>,
filter: &'c NetworkFilter,
after: &Option<String>,
before: &Option<String>,
after: Option<&str>,
before: Option<&str>,
first: Option<usize>,
last: Option<usize>,
) -> Result<(std::iter::Peekable<FilteredIter<'c, T>>, usize)>
Expand All @@ -472,8 +472,8 @@
fn get_filtered_iter<'c, T>(
store: &RawEventStore<'c, T>,
filter: &'c NetworkFilter,
after: &Option<String>,
before: &Option<String>,
after: Option<&str>,
before: Option<&str>,
first: Option<usize>,
last: Option<usize>,
) -> Result<(FilteredIter<'c, T>, Option<Vec<u8>>, usize)>
Expand Down Expand Up @@ -626,7 +626,7 @@
Ok(String::from_utf8_lossy(&output.stdout).into_owned())
}

fn check_address(filter_addr: &Option<IpRange>, target_addr: Option<IpAddr>) -> Result<bool> {
fn check_address(filter_addr: Option<&IpRange>, target_addr: Option<IpAddr>) -> Result<bool> {
if let Some(ip_range) = filter_addr {
if let Some(addr) = target_addr {
if let Some(start) = ip_range.start.as_deref() {
Expand All @@ -646,7 +646,7 @@
Ok(true)
}

fn check_port(filter_port: &Option<PortRange>, target_port: Option<u16>) -> bool {
fn check_port(filter_port: Option<&PortRange>, target_port: Option<u16>) -> bool {
if let Some(port_range) = filter_port {
if let Some(port) = target_port {
if let Some(start) = port_range.start {
Expand All @@ -660,17 +660,17 @@
true
}

fn check_contents(filter_str: &Option<String>, target_str: Option<String>) -> bool {
fn check_contents(filter_str: Option<&str>, target_str: Option<String>) -> bool {
filter_str.as_ref().map_or(true, |filter_str| {
target_str.map_or(false, |contents| contents.contains(filter_str))
target_str.map_or(false, |contents| contents.contains(*filter_str))

Check warning on line 665 in src/graphql.rs

View check run for this annotation

Codecov / codecov/patch

src/graphql.rs#L665

Added line #L665 was not covered by tests
})
}

fn check_agent_id(filter_agent_id: &Option<String>, target_agent_id: &Option<String>) -> bool {
fn check_agent_id(filter_agent_id: Option<&str>, target_agent_id: Option<&str>) -> bool {
filter_by_str(filter_agent_id, target_agent_id)
}

fn filter_by_str(filter_str: &Option<String>, target_str: &Option<String>) -> bool {
fn filter_by_str(filter_str: Option<&str>, target_str: Option<&str>) -> bool {
filter_str.as_ref().map_or(true, |filter_id| {
target_str
.as_ref()
Expand Down Expand Up @@ -809,7 +809,7 @@
$(, with_extra_handler_args ($($handler_arg:expr ),* ))?
$(, with_extra_query_args ($($query_arg:tt := $query_arg_from:expr),* ))? ) => {{
if $request_from_peer.unwrap_or_default() {
return $handler($ctx, &$sensors, $($($handler_arg,)*)*).await;
return $handler($ctx, $sensors.as_ref(), $($($handler_arg,)*)*).await;
}

let sensors_set: HashSet<_> = $sensors.iter().map(|s| s.as_str()).collect();
Expand All @@ -821,7 +821,7 @@
!peers_in_charge_graphql_addrs.is_empty(),
) {
(true, true) => {
let current_giganto_result_fut = $handler($ctx, &sensors_to_handle_by_current_giganto, $($($handler_arg,)*)*);
let current_giganto_result_fut = $handler($ctx, sensors_to_handle_by_current_giganto.as_ref(), $($($handler_arg,)*)*);

let peer_results_fut = crate::graphql::request_selected_peers_for_events_fut!(
$ctx,
Expand Down Expand Up @@ -875,7 +875,7 @@
Ok(peer_results.into_iter().flatten().collect())
}
(true, false) => {
$handler($ctx, &sensors_to_handle_by_current_giganto, $($($handler_arg,)*)*).await
$handler($ctx, sensors_to_handle_by_current_giganto.as_ref(), $($($handler_arg,)*)*).await
}
(false, false) => Ok(Vec::new()),
}
Expand Down Expand Up @@ -1165,7 +1165,7 @@
fn combine_results<N>(
current_giganto_result: Connection<String, N>,
peer_results: Vec<Connection<String, N>>,
before: &Option<String>,
before: Option<&str>,

Check warning on line 1168 in src/graphql.rs

View check run for this annotation

Codecov / codecov/patch

src/graphql.rs#L1168

Added line #L1168 was not covered by tests
first: Option<i32>,
last: Option<i32>,
) -> Connection<String, N>
Expand Down Expand Up @@ -1208,7 +1208,7 @@
#[allow(unused)]
fn sort_and_trunk_edges<N>(
mut edges: Vec<Edge<String, N, EmptyFields>>,
before: &Option<String>,
before: Option<&str>,
first: Option<i32>,
last: Option<i32>,
) -> Vec<Edge<String, N, EmptyFields>>
Expand Down Expand Up @@ -1752,63 +1752,52 @@
#[test]
fn test_sort_and_trunk_edges() {
let empty_vec = Vec::<Edge<String, TestNode, EmptyFields>>::new();
let result = sort_and_trunk_edges(empty_vec, &None, None, None);
let result = sort_and_trunk_edges(empty_vec, None, None, None);
assert!(result.is_empty());

let result = sort_and_trunk_edges(edges_fixture(), &None, None, None);
let result = sort_and_trunk_edges(edges_fixture(), None, None, None);
assert_eq!(result.len(), 6);
assert!(result.windows(2).all(|w| w[0].cursor < w[1].cursor));
assert_eq!(result[0].cursor, "danger_001".to_string());
assert_eq!(result[result.len() - 1].cursor, "warn_001".to_string());

let result = sort_and_trunk_edges(edges_fixture(), &None, Some(5), None);
let result = sort_and_trunk_edges(edges_fixture(), None, Some(5), None);
assert_eq!(result.len(), 5);
assert!(result.windows(2).all(|w| w[0].cursor < w[1].cursor));
assert_eq!(result[0].cursor, "danger_001".to_string());
assert_eq!(result[result.len() - 1].cursor, "info_003".to_string());

let result = sort_and_trunk_edges(edges_fixture(), &None, Some(10), None);
let result = sort_and_trunk_edges(edges_fixture(), None, Some(10), None);
assert_eq!(result.len(), 6);
assert!(result.windows(2).all(|w| w[0].cursor < w[1].cursor));
assert_eq!(result[0].cursor, "danger_001".to_string());
assert_eq!(result[result.len() - 1].cursor, "warn_001".to_string());

let result = sort_and_trunk_edges(edges_fixture(), &None, None, Some(5));
let result = sort_and_trunk_edges(edges_fixture(), None, None, Some(5));
assert_eq!(result.len(), 5);
assert!(result.windows(2).all(|w| w[0].cursor < w[1].cursor));
assert_eq!(result[0].cursor, "danger_002".to_string());
assert_eq!(result[result.len() - 1].cursor, "warn_001".to_string());

let result = sort_and_trunk_edges(edges_fixture(), &None, None, Some(10));
let result = sort_and_trunk_edges(edges_fixture(), None, None, Some(10));
assert_eq!(result.len(), 6);
assert!(result.windows(2).all(|w| w[0].cursor < w[1].cursor));
assert_eq!(result[0].cursor, "danger_001".to_string());
assert_eq!(result[result.len() - 1].cursor, "warn_001".to_string());

let result =
sort_and_trunk_edges(edges_fixture(), &Some("zebra_001".to_string()), None, None);
let result = sort_and_trunk_edges(edges_fixture(), Some("zebra_001"), None, None);
assert_eq!(result.len(), 6);
assert!(result.windows(2).all(|w| w[0].cursor < w[1].cursor));
assert_eq!(result[0].cursor, "danger_001".to_string());
assert_eq!(result[result.len() - 1].cursor, "warn_001".to_string());

let result = sort_and_trunk_edges(
edges_fixture(),
&Some("zebra_001".to_string()),
None,
Some(5),
);
let result = sort_and_trunk_edges(edges_fixture(), Some("zebra_001"), None, Some(5));
assert_eq!(result.len(), 5);
assert!(result.windows(2).all(|w| w[0].cursor < w[1].cursor));
assert_eq!(result[0].cursor, "danger_002".to_string());
assert_eq!(result[result.len() - 1].cursor, "warn_001".to_string());

let result = sort_and_trunk_edges(
edges_fixture(),
&Some("zebra_001".to_string()),
None,
Some(10),
);
let result = sort_and_trunk_edges(edges_fixture(), Some("zebra_001"), None, Some(10));
assert_eq!(result.len(), 6);
assert!(result.windows(2).all(|w| w[0].cursor < w[1].cursor));
assert_eq!(result[0].cursor, "danger_001".to_string());
Expand Down
10 changes: 5 additions & 5 deletions src/graphql/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1640,11 +1640,11 @@
_sensor: Option<String>,
agent_id: Option<String>,
) -> Result<bool> {
if check_address(&self.orig_addr, orig_addr)?
&& check_address(&self.resp_addr, resp_addr)?
&& check_port(&self.orig_port, orig_port)
&& check_port(&self.resp_port, resp_port)
&& check_agent_id(&self.agent_id, &agent_id)
if check_address(self.orig_addr.as_ref(), orig_addr)?
&& check_address(self.resp_addr.as_ref(), resp_addr)?
&& check_port(self.orig_port.as_ref(), orig_port)
&& check_port(self.resp_port.as_ref(), resp_port)
&& check_agent_id(self.agent_id.as_deref(), agent_id.as_deref())

Check warning on line 1647 in src/graphql/export.rs

View check run for this annotation

Codecov / codecov/patch

src/graphql/export.rs#L1643-L1647

Added lines #L1643 - L1647 were not covered by tests
{
return Ok(true);
}
Expand Down
10 changes: 5 additions & 5 deletions src/graphql/netflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@
_sensor: Option<String>,
_agent_id: Option<String>,
) -> Result<bool> {
if check_address(&self.orig_addr, orig_addr)?
&& check_address(&self.resp_addr, resp_addr)?
&& check_port(&self.orig_port, orig_port)
&& check_port(&self.resp_port, resp_port)
&& check_contents(&self.contents, log_contents)
if check_address(self.orig_addr.as_ref(), orig_addr)?
&& check_address(self.resp_addr.as_ref(), resp_addr)?
&& check_port(self.orig_port.as_ref(), orig_port)
&& check_port(self.resp_port.as_ref(), resp_port)
&& check_contents(self.contents.as_deref(), log_contents)

Check warning on line 86 in src/graphql/netflow.rs

View check run for this annotation

Codecov / codecov/patch

src/graphql/netflow.rs#L82-L86

Added lines #L82 - L86 were not covered by tests
{
return Ok(true);
}
Expand Down
Loading