Skip to content

Commit

Permalink
RPPL-2100: Create JQ Rules for Secure Storage API (#555)
Browse files Browse the repository at this point in the history
* RPPL-2100: Create JQ Rules for Secure Storage API (#547)

* fix: error is not part of result

* fix: unittest

* build: cleanup

* fix: handle error in update_response()

* build: cleanup

* fix: handle error

* build: cleanup

* build: cleanup

* build: cleanup
  • Loading branch information
SKumarMetro authored Jul 1, 2024
1 parent 5de6489 commit 57fcfcb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
20 changes: 14 additions & 6 deletions core/main/src/broker/endpoint_broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,16 +446,24 @@ impl BrokerOutputForwarder {
.transform
.get_filter(super::rules_engine::RuleTransformType::Response)
{
if let Ok(r) = jq_compile(
result,
match jq_compile(
result.clone(),
&filter,
format!("{}_response", rpc_request.ctx.method),
) {
if r.to_string().to_lowercase().contains("null") {
v.data.result = Some(Value::Null)
} else {
v.data.result = Some(r);
Ok(r) => {
if r.to_string().to_lowercase().contains("null") {
v.data.error = None;
v.data.result = Some(Value::Null);
} else if result.get("success").is_some() {
v.data.result = Some(r);
v.data.error = None;
} else {
v.data.error = Some(r);
v.data.result = None;
}
}
Err(e) => error!("jq_compile error {:?}", e),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions core/main/src/broker/thunder_broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ impl ThunderBroker {
let mut new_response = response.clone();
if response.params.is_some() {
new_response.result = response.params.clone();
} else if response.error.is_some() {
new_response.result = response.error.clone();
}
new_response
}
Expand Down
4 changes: 1 addition & 3 deletions device/mock_device/src/mock_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl ParamResponse {
if let Some(e) = self.error.clone() {
sink_responses.push(ResponseSink {
delay: 0,
data: json!({"jsonrpc": "2.0", "id": id, "error": [e]}),
data: json!({"jsonrpc": "2.0", "id": id, "error": e}),
});
} else if let Some(v) = self.result.clone() {
sink_responses.push(ResponseSink {
Expand Down Expand Up @@ -273,8 +273,6 @@ mod tests {
.data
.get("error")
.unwrap()
.as_array()
.unwrap()[0]
.get("code")
.unwrap()
.as_i64()
Expand Down

0 comments on commit 57fcfcb

Please sign in to comment.