Skip to content

Commit 78b7315

Browse files
Merge pull request #189 from code0-tech/185-add-body-validation
Add Test Execution Body Validation
2 parents 8ce4142 + 2521242 commit 78b7315

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

Cargo.lock

Lines changed: 8 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ env_logger = "0.11.8"
1111
prost = "0.14.1"
1212
tonic = "0.14.1"
1313
tucana = { version = "0.0.33", features = ["all"] }
14-
code0-flow = { version = "0.0.14" }
14+
code0-flow = { version = "0.0.16" }
1515
serde_json = "1.0.140"
1616
async-nats = "0.42.0"
1717
tonic-health = "0.14.1"

src/sagittarius/test_execution_client_impl.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
use futures::StreamExt;
88
use prost::Message;
99
use std::sync::Arc;
10+
use std::time::SystemTime;
11+
use code0_flow::flow_validator::verify_flow;
1012
use tokio_stream::wrappers::ReceiverStream;
1113
use tonic::Request;
1214
use tonic::transport::Channel;
1315
use tucana::sagittarius::execution_logon_request::Data;
1416
use tucana::sagittarius::execution_service_client::ExecutionServiceClient;
15-
use tucana::sagittarius::{ExecutionLogonRequest, Logon, TestExecutionResponse};
17+
use tucana::sagittarius::{ExecutionLogonRequest, Log, Logon, TestExecutionResponse};
1618
use tucana::shared::{ExecutionFlow, ValidationFlow, Value};
1719

1820
pub struct SagittariusTestExecutionServiceClient {
@@ -90,11 +92,38 @@ impl SagittariusTestExecutionServiceClient {
9092
let validation_flow = match self.load_validation_flow(request.flow_id).await {
9193
Some(flow) => flow,
9294
None => {
93-
return;
95+
continue;
9496
}
9597
};
9698

9799
let uuid = uuid::Uuid::new_v4().to_string();
100+
101+
if let Some(body) = &request.body {
102+
if let Err(rule_violations) = verify_flow(validation_flow.clone(), body.clone()) {
103+
104+
let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_millis().to_string();
105+
let log = Log {
106+
level: "error".to_string(),
107+
timestamp: now,
108+
message: rule_violations.to_string(),
109+
};
110+
111+
let execution_result = ExecutionLogonRequest {
112+
data: Some(Data::Response(TestExecutionResponse {
113+
flow_id: request.flow_id,
114+
execution_uuid: uuid,
115+
result: None,
116+
logs: vec![log],
117+
})),
118+
};
119+
120+
if let Err(err) = tx.send(execution_result).await {
121+
log::error!("Failed to send ExecutionLogonResponse: {:?}", err);
122+
}
123+
continue
124+
}
125+
}
126+
98127
let execution_flow = ExecutionFlow {
99128
flow_id: request.flow_id,
100129
starting_node: validation_flow.starting_node,

0 commit comments

Comments
 (0)