diff --git a/Cargo.lock b/Cargo.lock index b03af22a..0b2599d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2119,7 +2119,7 @@ dependencies = [ [[package]] name = "hipcheck-common" -version = "0.1.0" +version = "0.2.0" dependencies = [ "anyhow", "log", @@ -2142,7 +2142,7 @@ dependencies = [ [[package]] name = "hipcheck-sdk" -version = "0.2.0" +version = "0.3.0" dependencies = [ "anyhow", "console", diff --git a/hipcheck-common/Cargo.toml b/hipcheck-common/Cargo.toml index a3eef98c..d883274b 100644 --- a/hipcheck-common/Cargo.toml +++ b/hipcheck-common/Cargo.toml @@ -2,7 +2,7 @@ name = "hipcheck-common" description = "Common functionality for the Hipcheck gRPC protocol" repository = "https://github.com/mitre/hipcheck" -version = "0.1.0" +version = "0.2.0" license = "Apache-2.0" edition = "2021" diff --git a/hipcheck-common/proto/hipcheck/v1/hipcheck.proto b/hipcheck-common/proto/hipcheck/v1/hipcheck.proto index 63f043c8..41b42775 100644 --- a/hipcheck-common/proto/hipcheck/v1/hipcheck.proto +++ b/hipcheck-common/proto/hipcheck/v1/hipcheck.proto @@ -192,8 +192,11 @@ enum QueryState { // Something has gone wrong. QUERY_STATE_UNSPECIFIED = 0; - // We are submitting a new query. - QUERY_STATE_SUBMIT = 1; + // We are sending a query to a plugin and we are expecting to need to send more chunks + QUERY_STATE_SUBMIT_IN_PROGRESS = 4; + + // We are completed submitting a new query. + QUERY_STATE_SUBMIT_COMPLETE = 1; // We are replying to a query and expect more chunks. QUERY_STATE_REPLY_IN_PROGRESS = 2; diff --git a/hipcheck-common/src/chunk.rs b/hipcheck-common/src/chunk.rs index 7d7967ab..555ae464 100644 --- a/hipcheck-common/src/chunk.rs +++ b/hipcheck-common/src/chunk.rs @@ -36,11 +36,20 @@ fn estimate_size(msg: &PluginQuery) -> usize { } pub fn chunk_with_size(msg: PluginQuery, max_est_size: usize) -> Result> { - // Chunking only does something on response objects, mostly because - // we don't have a state to represent "SubmitInProgress" - if msg.state == QueryState::Submit as i32 { - return Ok(vec![msg]); - } + // in_progress_state - the state the PluginQuery is in for all queries in the resulting Vec, + // EXCEPT the last one + // + // completion_state - the state the PluginQuery is in if it is the last chunked message + let (in_progress_state, completion_state) = match msg.state() { + // if the message gets chunked, then it must either be a reply or submission that is in process + QueryState::Unspecified => return Err(anyhow!("msg in Unspecified query state")), + QueryState::SubmitInProgress | QueryState::SubmitComplete => { + (QueryState::SubmitInProgress, QueryState::SubmitComplete) + } + QueryState::ReplyInProgress | QueryState::ReplyComplete => { + (QueryState::ReplyInProgress, QueryState::ReplyComplete) + } + }; let mut out: Vec = vec![]; let mut base: PluginQuery = msg; @@ -58,9 +67,9 @@ pub fn chunk_with_size(msg: PluginQuery, max_est_size: usize) -> Result Result 0 && base.key.bytes().len() > 0 { // steal from key - query.key = drain_at_most_n_bytes(&mut base.key, remaining)?; - remaining -= query.key.bytes().len(); + chunked_query.key = drain_at_most_n_bytes(&mut base.key, remaining)?; + remaining -= chunked_query.key.bytes().len(); made_progress = true; } if remaining > 0 && base.output.bytes().len() > 0 { // steal from output - query.output = drain_at_most_n_bytes(&mut base.output, remaining)?; - remaining -= query.output.bytes().len(); + chunked_query.output = drain_at_most_n_bytes(&mut base.output, remaining)?; + remaining -= chunked_query.output.bytes().len(); made_progress = true; } - let mut l = base.concern.len(); // While we still want to steal more bytes and we have more elements of // `concern` to possibly steal - while remaining > 0 && l > 0 { - let i = l - 1; - + let mut i = 0; + while remaining > 0 && i < base.concern.len() { let c_bytes = base.concern.get(i).unwrap().bytes().len(); if c_bytes > max_est_size { @@ -96,19 +103,24 @@ pub fn chunk_with_size(msg: PluginQuery, max_est_size: usize) -> Result Result> { chunk(msg.try_into()?) } +/// Determine whether or not the given `QueryState` represents an intermediate InProgress state +fn in_progress_state(state: &QueryState) -> bool { + matches!( + state, + QueryState::ReplyInProgress | QueryState::SubmitInProgress + ) +} + #[derive(Default)] pub struct QuerySynthesizer { raw: Option, @@ -138,14 +158,16 @@ impl QuerySynthesizer { }; } let raw = self.raw.as_mut().unwrap(); // We know its `Some`, was set above - let mut state = raw + let initial_state: QueryState = raw .state .try_into() .map_err(|_| Error::UnspecifiedQueryState)?; + // holds state of current chunk + let mut current_state: QueryState = initial_state; // If response is the first of a set of chunks, handle - if matches!(state, QueryState::ReplyInProgress) { - while matches!(state, QueryState::ReplyInProgress) { + if in_progress_state(¤t_state) { + while in_progress_state(¤t_state) { // We expect another message. Pull it off the existing queue, // or get a new one if we have run out let next = match chunks.next() { @@ -156,20 +178,40 @@ impl QuerySynthesizer { }; // By now we have our "next" message - state = next + current_state = next .state .try_into() .map_err(|_| Error::UnspecifiedQueryState)?; - match state { - QueryState::Unspecified => return Err(Error::UnspecifiedQueryState), - QueryState::Submit => return Err(Error::ReceivedSubmitWhenExpectingReplyChunk), - QueryState::ReplyInProgress | QueryState::ReplyComplete => { - if state == QueryState::ReplyComplete { - raw.state = QueryState::ReplyComplete.into(); + match (initial_state, current_state) { + // error out if any states are unspecified + (QueryState::Unspecified, _) | (_, QueryState::Unspecified) => { + return Err(Error::UnspecifiedQueryState) + } + // error out if expecting a Submit messages and a Reply is received + (QueryState::SubmitInProgress, QueryState::ReplyInProgress) + | (QueryState::SubmitInProgress, QueryState::ReplyComplete) + | (QueryState::SubmitComplete, QueryState::ReplyInProgress) + | (QueryState::SubmitComplete, QueryState::ReplyComplete) => { + return Err(Error::ReceivedReplyWhenExpectingSubmitChunk) + } + // error out if expecting a Reply message and Submit is received + (QueryState::ReplyInProgress, QueryState::SubmitInProgress) + | (QueryState::ReplyInProgress, QueryState::SubmitComplete) + | (QueryState::ReplyComplete, QueryState::SubmitInProgress) + | (QueryState::ReplyComplete, QueryState::SubmitComplete) => { + return Err(Error::ReceivedSubmitWhenExpectingReplyChunk) + } + // otherwise we got an expected message type + (_, _) => { + if current_state == QueryState::ReplyComplete { + raw.set_state(QueryState::ReplyComplete); + } + if current_state == QueryState::SubmitComplete { + raw.set_state(QueryState::SubmitComplete); } raw.key.push_str(next.key.as_str()); raw.output.push_str(next.output.as_str()); - raw.concern.extend_from_slice(next.concern.as_slice()); + raw.concern.extend(next.concern); } }; } @@ -181,7 +223,6 @@ impl QuerySynthesizer { }); } } - self.raw.take().unwrap().try_into().map(Some) } } @@ -209,23 +250,44 @@ mod test { #[test] fn test_chunking() { - let query = PluginQuery { - id: 0, - state: QueryState::ReplyComplete as i32, - publisher_name: "".to_owned(), - plugin_name: "".to_owned(), - query_name: "".to_owned(), - // This key will cause the chunk not to occur on a char boundary - key: "aこれは実験です".to_owned(), - output: "".to_owned(), - concern: vec!["< 10".to_owned(), "0123456789".to_owned()], - }; - let res = match chunk_with_size(query, 10) { - Ok(r) => r, - Err(e) => { - panic!("{e}"); - } - }; - assert_eq!(res.len(), 4); + // test both reply and submission chunking + let states = [ + (QueryState::SubmitInProgress, QueryState::SubmitComplete), + (QueryState::ReplyInProgress, QueryState::ReplyComplete), + ]; + + for (intermediate_state, final_state) in states.into_iter() { + let orig_query = PluginQuery { + id: 0, + state: final_state as i32, + publisher_name: "".to_owned(), + plugin_name: "".to_owned(), + query_name: "".to_owned(), + // This key will cause the chunk not to occur on a char boundary + key: serde_json::to_string("aこれは実験です").unwrap(), + output: serde_json::to_string("").unwrap(), + concern: vec!["< 10".to_owned(), "0123456789".to_owned()], + }; + let res = match chunk_with_size(orig_query.clone(), 10) { + Ok(r) => r, + Err(e) => { + panic!("{e}"); + } + }; + // ensure first 4 are ...InProgress + assert_eq!( + res.iter() + .filter(|x| x.state() == intermediate_state) + .count(), + 4 + ); + // ensure last one is ...Complete + assert_eq!(res.last().unwrap().state(), final_state); + assert_eq!(res.len(), 5); + // attempt to reassemble message + let mut synth = QuerySynthesizer::default(); + let synthesized_query = synth.add(res.into_iter()).unwrap(); + assert_eq!(orig_query, synthesized_query.unwrap().try_into().unwrap()); + } } } diff --git a/hipcheck-common/src/error.rs b/hipcheck-common/src/error.rs index 5fcbb3a0..09242f00 100644 --- a/hipcheck-common/src/error.rs +++ b/hipcheck-common/src/error.rs @@ -11,10 +11,18 @@ pub enum Error { #[error("unexpected ReplyInProgress state for query")] UnexpectedReplyInProgress, + /// The `PluginEngine` received a message with the unexpected status `RequestInProgress` + #[error("unexpected RequestInProgress state for query")] + UnexpectedRequestInProgress, + /// The `PluginEngine` received a message with a request-type status when it expected a reply #[error("remote sent QuerySubmit when reply chunk expected")] ReceivedSubmitWhenExpectingReplyChunk, + /// The `PluginEngine` received a message with a reply-type status when it expected a submit + #[error("remote sent QueryReply when submit chunk expected")] + ReceivedReplyWhenExpectingSubmitChunk, + /// The `PluginEngine` received additional messages when it did not expect any #[error("received additional message for ID '{id}' after query completion")] MoreAfterQueryComplete { id: usize }, diff --git a/hipcheck-common/src/types.rs b/hipcheck-common/src/types.rs index 6944959a..3e9de4a0 100644 --- a/hipcheck-common/src/types.rs +++ b/hipcheck-common/src/types.rs @@ -29,7 +29,8 @@ impl TryFrom for QueryDirection { fn try_from(value: QueryState) -> Result { match value { QueryState::Unspecified => Err(Error::UnspecifiedQueryState), - QueryState::Submit => Ok(QueryDirection::Request), + QueryState::SubmitInProgress => Err(Error::UnexpectedRequestInProgress), + QueryState::SubmitComplete => Ok(QueryDirection::Request), QueryState::ReplyInProgress => Err(Error::UnexpectedReplyInProgress), QueryState::ReplyComplete => Ok(QueryDirection::Response), } @@ -39,7 +40,7 @@ impl TryFrom for QueryDirection { impl From for QueryState { fn from(value: QueryDirection) -> Self { match value { - QueryDirection::Request => QueryState::Submit, + QueryDirection::Request => QueryState::SubmitComplete, QueryDirection::Response => QueryState::ReplyComplete, } } @@ -49,15 +50,18 @@ impl TryFrom for Query { type Error = Error; fn try_from(value: PluginQuery) -> Result { + let direction = QueryDirection::try_from(value.state())?; + let key = serde_json::from_str(&value.key).map_err(Error::InvalidJsonInQueryKey)?; + let output = + serde_json::from_str(&value.output).map_err(Error::InvalidJsonInQueryOutput)?; Ok(Query { id: value.id as usize, - direction: QueryDirection::try_from(value.state())?, + direction, publisher: value.publisher_name, plugin: value.plugin_name, query: value.query_name, - key: serde_json::from_str(value.key.as_str()).map_err(Error::InvalidJsonInQueryKey)?, - output: serde_json::from_str(value.output.as_str()) - .map_err(Error::InvalidJsonInQueryOutput)?, + key, + output, concerns: value.concern, }) } diff --git a/hipcheck/Cargo.toml b/hipcheck/Cargo.toml index 08d15da1..2fc11d77 100644 --- a/hipcheck/Cargo.toml +++ b/hipcheck/Cargo.toml @@ -141,7 +141,7 @@ xz2 = "0.1.7" zip = "2.2.2" zip-extensions = "0.8.1" zstd = "0.13.2" -hipcheck-common = { version = "0.1.0", path = "../hipcheck-common" } +hipcheck-common = { version = "0.2.0", path = "../hipcheck-common" } serde_with = "3.11.0" [build-dependencies] diff --git a/plugins/activity/Cargo.toml b/plugins/activity/Cargo.toml index b2bdc4fd..8fc890c9 100644 --- a/plugins/activity/Cargo.toml +++ b/plugins/activity/Cargo.toml @@ -8,7 +8,7 @@ publish = false [dependencies] clap = { version = "4.5.23", features = ["derive"] } -hipcheck-sdk = { version = "0.2.0", path = "../../sdk/rust", features = [ +hipcheck-sdk = { version = "0.3.0", path = "../../sdk/rust", features = [ "macros", ] } jiff = { version = "0.1.14", features = ["serde"] } @@ -19,6 +19,6 @@ serde_json = "1.0.134" tokio = { version = "1.42.0", features = ["rt"] } [dev-dependencies] -hipcheck-sdk = { version = "0.2.0", path = "../../sdk/rust", features = [ +hipcheck-sdk = { version = "0.3.0", path = "../../sdk/rust", features = [ "mock_engine", ] } diff --git a/plugins/affiliation/Cargo.toml b/plugins/affiliation/Cargo.toml index 7c39cf01..c0c2d615 100644 --- a/plugins/affiliation/Cargo.toml +++ b/plugins/affiliation/Cargo.toml @@ -9,7 +9,7 @@ publish = false [dependencies] anyhow = "1.0.95" clap = { version = "4.5.23", features = ["derive"] } -hipcheck-sdk = { version = "0.2.0", path = "../../sdk/rust", features = [ +hipcheck-sdk = { version = "0.3.0", path = "../../sdk/rust", features = [ "macros", ] } kdl = "4.7.1" @@ -22,7 +22,7 @@ strum = { version = "0.26.3", features = ["derive"] } tokio = { version = "1.42.0", features = ["rt"] } [dev-dependencies] -hipcheck-sdk = { version = "0.2.0", path = "../../sdk/rust", features = [ +hipcheck-sdk = { version = "0.3.0", path = "../../sdk/rust", features = [ "macros", "mock_engine", ] } diff --git a/plugins/binary/Cargo.toml b/plugins/binary/Cargo.toml index bb0207b6..41d7748f 100644 --- a/plugins/binary/Cargo.toml +++ b/plugins/binary/Cargo.toml @@ -9,7 +9,7 @@ publish = false [dependencies] clap = { version = "4.5.23", features = ["derive"] } content_inspector = "0.2.4" -hipcheck-sdk = { version = "0.2.0", path = "../../sdk/rust", features = [ +hipcheck-sdk = { version = "0.3.0", path = "../../sdk/rust", features = [ "macros", ] } log = "0.4.22" @@ -22,6 +22,6 @@ toml = "0.8.19" walkdir = "2.5.0" [dev-dependencies] -hipcheck-sdk = { version = "0.2.0", path = "../../sdk/rust", features = [ +hipcheck-sdk = { version = "0.3.0", path = "../../sdk/rust", features = [ "mock_engine", ] } diff --git a/plugins/churn/Cargo.toml b/plugins/churn/Cargo.toml index 67b2e696..8cd7d654 100644 --- a/plugins/churn/Cargo.toml +++ b/plugins/churn/Cargo.toml @@ -8,7 +8,7 @@ publish = false [dependencies] clap = { version = "4.5.23", features = ["derive"] } -hipcheck-sdk = { version = "0.2.0", path = "../../sdk/rust", features = [ +hipcheck-sdk = { version = "0.3.0", path = "../../sdk/rust", features = [ "macros", ] } log = "0.4.22" @@ -20,7 +20,7 @@ tokio = { version = "1.42.0", features = ["rt"] } toml = "0.8.19" [dev-dependencies] -hipcheck-sdk = { version = "0.2.0", path = "../../sdk/rust", features = [ +hipcheck-sdk = { version = "0.3.0", path = "../../sdk/rust", features = [ "mock_engine", ] } pathbuf = "1.0.0" diff --git a/plugins/entropy/Cargo.toml b/plugins/entropy/Cargo.toml index 4302eaa0..facd9d1a 100644 --- a/plugins/entropy/Cargo.toml +++ b/plugins/entropy/Cargo.toml @@ -12,7 +12,7 @@ clap = { version = "4.5.23", features = ["derive"] } dashmap = { version = "6.1.0", features = ["inline", "rayon"] } finl_unicode = { version = "1.3.0", features = ["grapheme_clusters"] } futures = "0.3.31" -hipcheck-sdk = { version = "0.2.0", path = "../../sdk/rust", features = [ +hipcheck-sdk = { version = "0.3.0", path = "../../sdk/rust", features = [ "macros", ] } ordered-float = { version = "4.5.0", features = ["serde"] } @@ -27,7 +27,7 @@ toml = "0.8.19" unicode-normalization = "0.1.24" [dev-dependencies] -hipcheck-sdk = { version = "0.2.0", path = "../../sdk/rust", features = [ +hipcheck-sdk = { version = "0.3.0", path = "../../sdk/rust", features = [ "macros", "mock_engine", ] } diff --git a/plugins/fuzz/Cargo.toml b/plugins/fuzz/Cargo.toml index 343fa8d5..24613964 100644 --- a/plugins/fuzz/Cargo.toml +++ b/plugins/fuzz/Cargo.toml @@ -8,7 +8,7 @@ publish = false [dependencies] clap = { version = "4.5.23", features = ["derive"] } -hipcheck-sdk = { version = "0.2.0", path = "../../sdk/rust", features = [ +hipcheck-sdk = { version = "0.3.0", path = "../../sdk/rust", features = [ "macros", ] } serde = { version = "1.0.215", features = ["derive"] } @@ -16,7 +16,7 @@ serde_json = "1.0.134" tokio = { version = "1.42.0", features = ["rt"] } [dev-dependencies] -hipcheck-sdk = { version = "0.2.0", path = "../../sdk/rust", features = [ +hipcheck-sdk = { version = "0.3.0", path = "../../sdk/rust", features = [ "macros", "mock_engine", ] } diff --git a/plugins/git/Cargo.toml b/plugins/git/Cargo.toml index 8591c2db..f9801e00 100644 --- a/plugins/git/Cargo.toml +++ b/plugins/git/Cargo.toml @@ -9,10 +9,14 @@ publish = false [dependencies] anyhow = "1.0.95" clap = { version = "4.5.23", features = ["derive"] } -hipcheck-sdk = { version = "0.2.0", path = "../../sdk/rust", features = [ +hipcheck-sdk = { version = "0.3.0", path = "../../sdk/rust", features = [ "macros", ] } -gix = { version = "0.68.0", default-features = false, features = ["basic", "max-control", "zlib-stock"] } +gix = { version = "0.68.0", default-features = false, features = [ + "basic", + "max-control", + "zlib-stock", +] } jiff = { version = "0.1.14", features = ["serde"] } log = "0.4.22" once_cell = "1.10.0" diff --git a/plugins/github/Cargo.toml b/plugins/github/Cargo.toml index 5c63bc53..2745711b 100644 --- a/plugins/github/Cargo.toml +++ b/plugins/github/Cargo.toml @@ -10,7 +10,7 @@ publish = false anyhow = "1.0.95" clap = { version = "4.5.23", features = ["derive"] } graphql_client = "0.14.0" -hipcheck-sdk = { version = "0.2.0", path = "../../sdk/rust", features = [ +hipcheck-sdk = { version = "0.3.0", path = "../../sdk/rust", features = [ "macros", ] } log = "0.4.22" diff --git a/plugins/identity/Cargo.toml b/plugins/identity/Cargo.toml index d22a34af..b141d5c3 100644 --- a/plugins/identity/Cargo.toml +++ b/plugins/identity/Cargo.toml @@ -8,7 +8,7 @@ publish = false [dependencies] clap = { version = "4.5.23", features = ["derive"] } -hipcheck-sdk = { version = "0.2.0", path = "../../sdk/rust", features = [ +hipcheck-sdk = { version = "0.3.0", path = "../../sdk/rust", features = [ "macros", ] } log = "0.4.22" @@ -19,6 +19,6 @@ tokio = { version = "1.42.0", features = ["rt"] } toml = "0.8.19" [dev-dependencies] -hipcheck-sdk = { version = "0.2.0", path = "../../sdk/rust", features = [ +hipcheck-sdk = { version = "0.3.0", path = "../../sdk/rust", features = [ "mock_engine", ] } diff --git a/plugins/linguist/Cargo.toml b/plugins/linguist/Cargo.toml index ceec40be..11e78a65 100644 --- a/plugins/linguist/Cargo.toml +++ b/plugins/linguist/Cargo.toml @@ -9,7 +9,7 @@ publish = false [dependencies] anyhow = "1.0.95" clap = { version = "4.5.23", features = ["derive"] } -hipcheck-sdk = { version = "0.2.0", path = "../../sdk/rust", features = [ +hipcheck-sdk = { version = "0.3.0", path = "../../sdk/rust", features = [ "macros", ] } log = "0.4.22" @@ -20,7 +20,7 @@ tokio = { version = "1.42.0", features = ["rt"] } toml = "0.8.19" [dev-dependencies] -hipcheck-sdk = { version = "0.2.0", path = "../../sdk/rust", features = [ +hipcheck-sdk = { version = "0.3.0", path = "../../sdk/rust", features = [ "macros", "mock_engine", ] } diff --git a/plugins/npm/Cargo.toml b/plugins/npm/Cargo.toml index 437ed0c6..db6cc3f7 100644 --- a/plugins/npm/Cargo.toml +++ b/plugins/npm/Cargo.toml @@ -9,7 +9,7 @@ publish = false [dependencies] anyhow = "1.0.95" clap = { version = "4.5.23", features = ["derive"] } -hipcheck-sdk = { version = "0.2.0", path = "../../sdk/rust", features = [ +hipcheck-sdk = { version = "0.3.0", path = "../../sdk/rust", features = [ "macros", ] } log = "0.4.22" diff --git a/plugins/review/Cargo.toml b/plugins/review/Cargo.toml index 94a60f4c..758da851 100644 --- a/plugins/review/Cargo.toml +++ b/plugins/review/Cargo.toml @@ -9,7 +9,7 @@ publish = false [dependencies] anyhow = "1.0.95" clap = { version = "4.5.23", features = ["derive"] } -hipcheck-sdk = { version = "0.2.0", path = "../../sdk/rust", features = [ +hipcheck-sdk = { version = "0.3.0", path = "../../sdk/rust", features = [ "macros", ] } log = "0.4.22" @@ -20,6 +20,6 @@ tokio = { version = "1.42.0", features = ["rt"] } url = "2.5.4" [dev-dependencies] -hipcheck-sdk = { version = "0.2.0", path = "../../sdk/rust", features = [ +hipcheck-sdk = { version = "0.3.0", path = "../../sdk/rust", features = [ "mock_engine", ] } diff --git a/plugins/typo/Cargo.toml b/plugins/typo/Cargo.toml index 7af440a8..801f5d09 100644 --- a/plugins/typo/Cargo.toml +++ b/plugins/typo/Cargo.toml @@ -9,7 +9,7 @@ publish = false [dependencies] anyhow = "1.0.95" clap = { version = "4.5.23", features = ["derive"] } -hipcheck-sdk = { version = "0.2.0", path = "../../sdk/rust", features = [ +hipcheck-sdk = { version = "0.3.0", path = "../../sdk/rust", features = [ "macros", ] } log = "0.4.22" @@ -22,6 +22,6 @@ toml = "0.8.19" url = "2.5.4" [dev-dependencies] -hipcheck-sdk = { version = "0.2.0", path = "../../sdk/rust", features = [ +hipcheck-sdk = { version = "0.3.0", path = "../../sdk/rust", features = [ "mock_engine", ] } diff --git a/sdk/rust/Cargo.toml b/sdk/rust/Cargo.toml index 411b89d1..d295e3e3 100644 --- a/sdk/rust/Cargo.toml +++ b/sdk/rust/Cargo.toml @@ -4,7 +4,7 @@ description = "SDK for writing Hipcheck plugins in Rust" homepage = "https://hipcheck.mitre.org" repository = "https://github.com/mitre/hipcheck" license = "Apache-2.0" -version = "0.2.0" +version = "0.3.0" edition = "2021" [dependencies] @@ -25,7 +25,7 @@ hipcheck-sdk-macros = { path = "../../hipcheck-sdk-macros", version = "0.1.0", o typify-macro = "0.2.0" url = { version = "2.5.4", features = ["serde"] } log = "0.4.22" -hipcheck-common = { version = "0.1.0", path = "../../hipcheck-common" } +hipcheck-common = { version = "0.2.0", path = "../../hipcheck-common" } console = "0.15.10" [features] diff --git a/sdk/rust/src/error.rs b/sdk/rust/src/error.rs index d823dcea..cc20ce52 100644 --- a/sdk/rust/src/error.rs +++ b/sdk/rust/src/error.rs @@ -71,8 +71,10 @@ impl From for Error { use hipcheck_common::error::Error::*; match value { UnspecifiedQueryState => Error::UnspecifiedQueryState, + UnexpectedRequestInProgress => Error::UnexpectedReplyInProgress, UnexpectedReplyInProgress => Error::UnexpectedReplyInProgress, ReceivedSubmitWhenExpectingReplyChunk => Error::ReceivedSubmitWhenExpectingReplyChunk, + ReceivedReplyWhenExpectingSubmitChunk => Error::ReceivedReplyWhenExpectingRequest, MoreAfterQueryComplete { id } => Error::MoreAfterQueryComplete { id }, InvalidJsonInQueryKey(s) => Error::InvalidJsonInQueryKey(s), InvalidJsonInQueryOutput(s) => Error::InvalidJsonInQueryOutput(s), diff --git a/sdk/rust/src/plugin_engine.rs b/sdk/rust/src/plugin_engine.rs index a2b14aca..705fa65a 100644 --- a/sdk/rust/src/plugin_engine.rs +++ b/sdk/rust/src/plugin_engine.rs @@ -431,7 +431,7 @@ impl HcSessionSocket { return Ok(HandleAction::ForwardMsgToExistingSession(tx)); } - if query.state() == QueryState::Submit { + if [QueryState::SubmitInProgress, QueryState::SubmitComplete].contains(&query.state()) { return Ok(HandleAction::CreateSession); } diff --git a/xtask/src/task/mod.rs b/xtask/src/task/mod.rs index f944fc57..67b77ddb 100644 --- a/xtask/src/task/mod.rs +++ b/xtask/src/task/mod.rs @@ -6,6 +6,6 @@ pub mod buf; pub mod changelog; pub mod check; pub mod ci; +pub mod manifest; pub mod rfd; pub mod site; -pub mod manifest;