Skip to content

Commit

Permalink
Modify the cluster_id type usize to Option<usize>
Browse files Browse the repository at this point in the history
  • Loading branch information
syncpark committed Jan 13, 2025
1 parent 3aebb1b commit 733a9b9
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ Versioning](https://semver.org/spec/v2.0.0.html).
- The `ip2location::DB` argument for `serve` no longer needs to be wrapped in
`Arc` and `Mutex`. This change simplifies the code and improves performance by
removing unnecessary locking.
- Modified the type of `cluster_id` field of the detection event structures from
`usize` to `Option<usize>`: `HttpThreat`, `ExtraThreat`, `NetworkThreat`,
`WindowsThreat`.
The GraphQL API for `WindowsThreat` event structure is changed to return `ID`
type instead of `usize` type value for the `cluster_id` field.
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ num-traits = "0.2"
reqwest = { version = "0.12", default-features = false, features = [
"rustls-tls-native-roots",
] }
review-database = { git = "https://github.com/petabi/review-database.git", rev = "35b9d80" }
review-database = { git = "https://github.com/petabi/review-database.git", rev = "f59bef0" }
roxy = { git = "https://github.com/aicers/roxy.git", tag = "0.3.0" }
rustls = { version = "0.23", default-features = false, features = [
"ring",
Expand Down
5 changes: 4 additions & 1 deletion src/graphql/event/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,10 @@ impl HttpThreat {
/// The cluster id of the event in string wthin the range representable
/// by a `usize`.
async fn cluster_id(&self) -> ID {
ID(self.inner.cluster_id.to_string())
ID(self
.inner
.cluster_id
.map_or(String::new(), |id| id.to_string()))

Check warning on line 205 in src/graphql/event/http.rs

View check run for this annotation

Codecov / codecov/patch

src/graphql/event/http.rs#L205

Added line #L205 was not covered by tests
}

async fn attack_kind(&self) -> &str {
Expand Down
5 changes: 4 additions & 1 deletion src/graphql/event/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ impl ExtraThreat {
/// The cluster id of the event in string wthin the range representable
/// by a `usize`.
async fn cluster_id(&self) -> ID {
ID(self.inner.cluster_id.to_string())
ID(self
.inner
.cluster_id
.map_or(String::new(), |id| id.to_string()))

Check warning on line 51 in src/graphql/event/log.rs

View check run for this annotation

Codecov / codecov/patch

src/graphql/event/log.rs#L51

Added line #L51 was not covered by tests
}

async fn attack_kind(&self) -> &str {
Expand Down
5 changes: 4 additions & 1 deletion src/graphql/event/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ impl NetworkThreat {
/// The cluster ID of the event in string within the representable
/// range of `usize`.
async fn cluster_id(&self) -> ID {
ID(self.inner.cluster_id.to_string())
ID(self
.inner
.cluster_id
.map_or(String::new(), |id| id.to_string()))

Check warning on line 115 in src/graphql/event/network.rs

View check run for this annotation

Codecov / codecov/patch

src/graphql/event/network.rs#L115

Added line #L115 was not covered by tests
}

async fn attack_kind(&self) -> &str {
Expand Down
9 changes: 6 additions & 3 deletions src/graphql/event/sysmon.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use async_graphql::Object;
use async_graphql::{Object, ID};
use chrono::{DateTime, Utc};
use review_database as database;

Expand Down Expand Up @@ -64,8 +64,11 @@ impl WindowsThreat {
&self.inner.matched_to
}

async fn cluster_id(&self) -> usize {
self.inner.cluster_id
async fn cluster_id(&self) -> ID {
ID(self
.inner
.cluster_id
.map_or(String::new(), |id| id.to_string()))

Check warning on line 71 in src/graphql/event/sysmon.rs

View check run for this annotation

Codecov / codecov/patch

src/graphql/event/sysmon.rs#L71

Added line #L71 was not covered by tests
}

async fn attack_kind(&self) -> &str {
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ struct ElementCount<'a> {
}

#[Object]
impl<'a> ElementCount<'a> {
impl ElementCount<'_> {
async fn value(&self) -> &str {
&self.inner.value
}
Expand Down

0 comments on commit 733a9b9

Please sign in to comment.