Skip to content

56 adjustents to tucana #57

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

Merged
merged 3 commits into from
May 29, 2025
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
2 changes: 1 addition & 1 deletion adapter/rest/src/.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ PORT=8081
REDIS_URL=redis://localhost:6379
RABBITMQ_URL=amqp://localhost:5672
AQUILA_URL=http://localhost:8080
IS_STATIC=true
IS_STATIC=false
27 changes: 6 additions & 21 deletions adapter/rest/src/queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub mod queue {
use std::{collections::HashMap, sync::Arc, time::Duration};
use tokio::sync::Mutex;
use tucana::shared::{Struct, Value};
use validator::{resolver::flow_resolver::resolve_flow, verify_flow};
use validator::verify_flow;

use crate::store::store::check_flow_exists;

Expand Down Expand Up @@ -88,31 +88,16 @@ pub mod queue {
}
}
}
// Determine which flow to use based on request body
let flow_to_use = if let Some(body) = &request.body {
// Verify flow

if let Some(body) = &request.body {
// Verify the rules of a Flow - this is only possible if a body exists
if let Err(err) = verify_flow(flow.clone(), body.clone()) {
return Some(HttpResponse::bad_request(err.to_string(), HashMap::new()));
}

// Resolve flow
let mut resolvable_flow = flow.clone();
match resolve_flow(&mut resolvable_flow, body.clone()) {
Ok(resolved_flow) => resolved_flow,
Err(_) => {
return Some(HttpResponse::internal_server_error(
"Internal Server Error".to_string(),
HashMap::new(),
))
}
}
} else {
// Use original flow if no body
flow
};
}

// Serialize flow
let json_flow = match serde_json::to_string(&flow_to_use) {
let json_flow = match serde_json::to_string(&flow) {
Ok(string) => string,
Err(err) => {
return Some(HttpResponse::internal_server_error(
Expand Down
10 changes: 4 additions & 6 deletions crates/validator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod resolver;
mod rules;

use rules::{
Expand Down Expand Up @@ -40,7 +39,7 @@ pub fn verify_flow(flow: Flow, body: Value) -> Result<(), DataTypeRuleError> {
}

//Verifies the rules on the datatype of the body thats given
pub fn verify_data_type_rules(
fn verify_data_type_rules(
body: Value,
data_type: DataType,
availabe_data_types: &Vec<DataType>,
Expand Down Expand Up @@ -98,9 +97,8 @@ pub fn verify_data_type_rules(
}
};
}
_ => {
todo!("Implement missing configs. (Question: should I skip input and return rule?)")
}
// Draco dont checks Node Rules (Input/Return Type Rules!)
_ => continue,
}
}

Expand All @@ -111,7 +109,7 @@ pub fn verify_data_type_rules(
}
}

pub fn get_data_type_by_id(data_types: &Vec<DataType>, str_id: &String) -> Option<DataType> {
fn get_data_type_by_id(data_types: &Vec<DataType>, str_id: &String) -> Option<DataType> {
let id = str_id.parse::<i32>().unwrap_or(1211);

data_types
Expand Down
67 changes: 0 additions & 67 deletions crates/validator/src/resolver/flow_resolver.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/validator/src/resolver/mod.rs

This file was deleted.

53 changes: 44 additions & 9 deletions crates/validator/src/rules/contains_key.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use super::violation::ContainsKeyRuleViolation;
use super::violation::DataTypeIdentifierNotPresentRuleViolation;
use super::violation::DataTypeRuleError;
use super::violation::DataTypeRuleViolation;
use super::violation::GenericKeyNotAllowedRuleViolation;
use super::violation::MissingDataTypeRuleDefinition;
use crate::get_data_type_by_id;
use crate::verify_data_type_rules;
use tucana::shared::data_type_identifier::Type;
use tucana::shared::helper::path::expect_kind;
use tucana::shared::value::Kind;
use tucana::shared::DataType;
Expand All @@ -29,16 +32,50 @@ pub fn apply_contains_key(
body: &Value,
available_data_types: &Vec<DataType>,
) -> Result<(), DataTypeRuleError> {
todo!("Adjsut to Generic Keys");
/*
let identifier = match rule.data_type_identifier {
Some(optional_data_type) => {
if let Some(data_type) = optional_data_type.r#type {
match data_type {
Type::DataTypeIdentifier(id) => id,
_ => {
return Err(DataTypeRuleError {
violations: vec![DataTypeRuleViolation::GenericKeyNotAllowed(
GenericKeyNotAllowedRuleViolation {
key: "identifier".to_string(),
},
)],
})
}
}
} else {
return Err(DataTypeRuleError {
violations: vec![DataTypeRuleViolation::DataTypeIdentifierNotPresent(
DataTypeIdentifierNotPresentRuleViolation {
identifier: "identifier".to_string(),
},
)],
});
}
}
None => {
return Err(DataTypeRuleError {
violations: vec![DataTypeRuleViolation::DataTypeIdentifierNotPresent(
DataTypeIdentifierNotPresentRuleViolation {
identifier: "identifier".to_string(),
},
)],
});
}
};

if let Some(Kind::StructValue(_)) = &body.kind {
let value = match expect_kind(&rule.data_type_identifier, &body) {
let value = match expect_kind(&identifier, &body) {
Some(value) => Value {
kind: Some(value.to_owned()),
},
None => {
let error = ContainsKeyRuleViolation {
missing_key: rule.data_type_identifier,
missing_key: identifier,
};

return Err(DataTypeRuleError {
Expand All @@ -47,12 +84,11 @@ pub fn apply_contains_key(
}
};

let data_type = match get_data_type_by_id(&available_data_types, &rule.data_type_identifier)
{
let data_type = match get_data_type_by_id(&available_data_types, &identifier) {
Some(data_type) => data_type,
None => {
let error = MissingDataTypeRuleDefinition {
missing_type: rule.data_type_identifier,
missing_type: identifier,
};

return Err(DataTypeRuleError {
Expand All @@ -66,10 +102,9 @@ pub fn apply_contains_key(
return Err(DataTypeRuleError {
violations: vec![DataTypeRuleViolation::ContainsKey(
ContainsKeyRuleViolation {
missing_key: rule.data_type_identifier.clone(),
missing_key: identifier,
},
)],
});
}
*/
}
55 changes: 46 additions & 9 deletions crates/validator/src/rules/contains_type.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use crate::{get_data_type_by_id, verify_data_type_rules};

use super::violation::{DataTypeRuleError, DataTypeRuleViolation, InvalidFormatRuleViolation};
use tucana::shared::{value::Kind, DataType, DataTypeContainsTypeRuleConfig, Value};
use super::violation::{
DataTypeIdentifierNotPresentRuleViolation, DataTypeRuleError, DataTypeRuleViolation,
GenericKeyNotAllowedRuleViolation, InvalidFormatRuleViolation,
};
use tucana::shared::{
data_type_identifier::Type, value::Kind, DataType, DataTypeContainsTypeRuleConfig, Value,
};

/// # Item of Collection Validation
///
Expand All @@ -18,15 +23,49 @@ pub fn apply_contains_type(
available_data_types: &Vec<DataType>,
body: &Value,
) -> Result<(), DataTypeRuleError> {
todo!("Adjust to generic keys");
/*
let identifier = match rule.data_type_identifier {
Some(optional_data_type) => {
if let Some(data_type) = optional_data_type.r#type {
match data_type {
Type::DataTypeIdentifier(id) => id,
_ => {
return Err(DataTypeRuleError {
violations: vec![DataTypeRuleViolation::GenericKeyNotAllowed(
GenericKeyNotAllowedRuleViolation {
key: "identifier".to_string(),
},
)],
})
}
}
} else {
return Err(DataTypeRuleError {
violations: vec![DataTypeRuleViolation::DataTypeIdentifierNotPresent(
DataTypeIdentifierNotPresentRuleViolation {
identifier: "identifier".to_string(),
},
)],
});
}
}
None => {
return Err(DataTypeRuleError {
violations: vec![DataTypeRuleViolation::DataTypeIdentifierNotPresent(
DataTypeIdentifierNotPresentRuleViolation {
identifier: "identifier".to_string(),
},
)],
});
}
};

let real_body = match &body.kind {
Some(body) => body.clone(),
None => {
return Err(DataTypeRuleError {
violations: vec![DataTypeRuleViolation::InvalidFormat(
InvalidFormatRuleViolation {
expected_format: rule.data_type_identifier,
expected_format: identifier,
value: String::from("other"),
},
)],
Expand All @@ -36,8 +75,7 @@ pub fn apply_contains_type(

match real_body {
Kind::ListValue(list) => {
let real_data_type =
get_data_type_by_id(available_data_types, &rule.data_type_identifier);
let real_data_type = get_data_type_by_id(available_data_types, &identifier);

if let Some(data_type) = real_data_type {
let mut rule_errors: Option<DataTypeRuleError> = None;
Expand All @@ -62,7 +100,7 @@ pub fn apply_contains_type(
return Err(DataTypeRuleError {
violations: vec![DataTypeRuleViolation::InvalidFormat(
InvalidFormatRuleViolation {
expected_format: rule.data_type_identifier,
expected_format: identifier,
value: String::from("other"),
},
)],
Expand All @@ -71,5 +109,4 @@ pub fn apply_contains_type(
}

Ok(())
*/
}
28 changes: 28 additions & 0 deletions crates/validator/src/rules/violation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ pub enum DataTypeRuleViolation {
NumberInRange(NumberInRangeRuleViolation),
ItemOfCollection(ItemOfCollectionRuleViolation),
InvalidFormat(InvalidFormatRuleViolation),
GenericKeyNotAllowed(GenericKeyNotAllowedRuleViolation),
DataTypeIdentifierNotPresent(DataTypeIdentifierNotPresentRuleViolation),
}

pub struct MissingDataTypeRuleDefinition {
Expand Down Expand Up @@ -46,6 +48,14 @@ pub struct InvalidFormatRuleViolation {
pub value: String,
}

pub struct GenericKeyNotAllowedRuleViolation {
pub key: String,
}

pub struct DataTypeIdentifierNotPresentRuleViolation {
pub identifier: String,
}

impl DataTypeRuleError {
pub fn to_string(&self) -> String {
let mut violations = Vec::new();
Expand Down Expand Up @@ -125,6 +135,24 @@ impl DataTypeRuleError {
}
}));
}
DataTypeRuleViolation::GenericKeyNotAllowed(v) => {
violations.push(serde_json::json!({
"type": "GenericKeyNotAllowed",
"explanation": format!("Generic key not allowed: '{}'", v.key),
"details": {
"key": v.key
}
}));
}
DataTypeRuleViolation::DataTypeIdentifierNotPresent(v) => {
violations.push(serde_json::json!({
"type": "DataTypeIdentifierNotPresent",
"explanation": format!("Data type identifier not present: '{}'", v.identifier),
"details": {
"identifier": v.identifier
}
}));
}
}
}

Expand Down