Skip to content
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

Validation of actuator type on actuate and batch_actuate and extend UpdateErrors #90

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
143 changes: 86 additions & 57 deletions databroker/src/broker.rs

Large diffs are not rendered by default.

20 changes: 18 additions & 2 deletions databroker/src/grpc/kuksa_val_v1/val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,11 +688,27 @@ fn convert_to_data_entry_error(path: &String, error: &broker::UpdateError) -> Da
message: "cannot set datapoint to value of unsupported type".to_string(),
}),
},
broker::UpdateError::OutOfBounds => DataEntryError {
broker::UpdateError::OutOfBoundsAllowed => DataEntryError {
path: path.clone(),
error: Some(proto::Error {
code: 400,
reason: String::from("value out of bounds"),
reason: String::from("value out of allowed bounds"),
message: String::from("given value exceeds type's boundaries"),
}),
},
broker::UpdateError::OutOfBoundsMinMax => DataEntryError {
path: path.clone(),
error: Some(proto::Error {
code: 400,
reason: String::from("value out of min/max bounds"),
message: String::from("given value exceeds type's boundaries"),
}),
},
broker::UpdateError::OutOfBoundsType => DataEntryError {
path: path.clone(),
error: Some(proto::Error {
code: 400,
reason: String::from("value out of type bounds"),
message: String::from("given value exceeds type's boundaries"),
}),
},
Expand Down
24 changes: 20 additions & 4 deletions databroker/src/grpc/kuksa_val_v2/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,17 @@ impl From<&broker::UpdateError> for proto::Error {
code: proto::ErrorCode::InvalidArgument.into(),
message: "Wrong Type".to_string(),
},
broker::UpdateError::OutOfBounds => proto::Error {
broker::UpdateError::OutOfBoundsAllowed => proto::Error {
code: proto::ErrorCode::InvalidArgument.into(),
message: "Out of Bounds".to_string(),
message: "Out of Bounds Allowed".to_string(),
},
broker::UpdateError::OutOfBoundsMinMax => proto::Error {
code: proto::ErrorCode::InvalidArgument.into(),
message: "Out of Bounds MinMax".to_string(),
},
broker::UpdateError::OutOfBoundsType => proto::Error {
code: proto::ErrorCode::InvalidArgument.into(),
message: "Out of Bounds Type".to_string(),
},
broker::UpdateError::UnsupportedType => proto::Error {
code: proto::ErrorCode::InvalidArgument.into(),
Expand Down Expand Up @@ -455,9 +463,17 @@ impl broker::UpdateError {
tonic::Code::InvalidArgument,
format!("Wrong type provided (id: {})", id),
),
broker::UpdateError::OutOfBounds => tonic::Status::new(
broker::UpdateError::OutOfBoundsAllowed => tonic::Status::new(
tonic::Code::InvalidArgument,
format!("Value out of allowed bounds (id: {})", id),
),
broker::UpdateError::OutOfBoundsMinMax => tonic::Status::new(
tonic::Code::InvalidArgument,
format!("Value out of min/max bounds (id: {})", id),
),
broker::UpdateError::OutOfBoundsType => tonic::Status::new(
tonic::Code::InvalidArgument,
format!("Value out of bounds (id: {})", id),
format!("Value out of type bounds (id: {})", id),
),
broker::UpdateError::UnsupportedType => tonic::Status::new(
tonic::Code::InvalidArgument,
Expand Down
3 changes: 2 additions & 1 deletion databroker/src/grpc/kuksa_val_v2/val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ impl proto::val_server::Val for broker::DataBroker {
// UNAVAILABLE if there is no provider currently providing the actuator
// DATA_LOSS is there is a internal TransmissionFailure
// INVALID_ARGUMENT
// - if the provided path is not an actuator.
// - if the data type used in the request does not match
// the data type of the addressed signal
// - if the requested value is not accepted,
Expand Down Expand Up @@ -1712,7 +1713,7 @@ mod tests {
// Handle the error from the publish_value function
assert_eq!(status.code(), tonic::Code::InvalidArgument);
// As of the today the first added datapoint get value 0 by default.
assert_eq!(status.message(), "Value out of bounds (id: 0)");
assert_eq!(status.message(), "Value out of min/max bounds (id: 0)");
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion databroker/src/grpc/sdv_databroker_v1/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,9 @@ impl From<&broker::UpdateError> for proto::DatapointError {
broker::UpdateError::WrongType | broker::UpdateError::UnsupportedType => {
proto::DatapointError::InvalidType
}
broker::UpdateError::OutOfBounds => proto::DatapointError::OutOfBounds,
broker::UpdateError::OutOfBoundsAllowed => proto::DatapointError::OutOfBounds,
broker::UpdateError::OutOfBoundsMinMax => proto::DatapointError::OutOfBounds,
broker::UpdateError::OutOfBoundsType => proto::DatapointError::OutOfBounds,
broker::UpdateError::PermissionDenied => proto::DatapointError::AccessDenied,
broker::UpdateError::PermissionExpired => proto::DatapointError::AccessDenied,
}
Expand Down
10 changes: 8 additions & 2 deletions databroker/src/viss/v2/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,14 @@ impl Viss for Server {
UpdateError::WrongType => Error::BadRequest {
msg: Some("Wrong data type.".into()),
},
UpdateError::OutOfBounds => Error::BadRequest {
msg: Some("Value out of bounds.".into()),
UpdateError::OutOfBoundsAllowed => Error::BadRequest {
msg: Some("Value out of allowed bounds.".into()),
},
UpdateError::OutOfBoundsMinMax => Error::BadRequest {
msg: Some("Value out of min/max bounds.".into()),
},
UpdateError::OutOfBoundsType => Error::BadRequest {
msg: Some("Value out of type bounds.".into()),
},
UpdateError::UnsupportedType => Error::BadRequest {
msg: Some("Unsupported data type.".into()),
Expand Down
9 changes: 8 additions & 1 deletion proto/kuksa/val/v2/val.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ service VAL {
// NOT_FOUND if the requested signal doesn't exist
// UNAUTHENTICATED if no credentials provided or credentials has expired
// PERMISSION_DENIED if access is denied
// INVALID_ARGUMENT if the request is empty or provided path is too long
// - MAX_REQUEST_PATH_LENGTH: usize = 1000;
//
rpc GetValue(GetValueRequest) returns (GetValueResponse);

Expand All @@ -39,6 +41,8 @@ service VAL {
// NOT_FOUND if any of the requested signals doesn't exist.
// UNAUTHENTICATED if no credentials provided or credentials has expired
// PERMISSION_DENIED if access is denied for any of the requested signals.
// INVALID_ARGUMENT if the request is empty or provided path is too long
// - MAX_REQUEST_PATH_LENGTH: usize = 1000;
//
rpc GetValues(GetValuesRequest) returns (GetValuesResponse);

Expand All @@ -48,6 +52,7 @@ service VAL {
// UNAUTHENTICATED if no credentials provided or credentials has expired
// PERMISSION_DENIED if access is denied for any of the signals.
// INVALID_ARGUMENT if the request is empty or provided path is too long
// - MAX_REQUEST_PATH_LENGTH: usize = 1000;
//
// When subscribing, Databroker shall immediately return the value for all
// subscribed entries.
Expand All @@ -60,7 +65,7 @@ service VAL {
// NOT_FOUND if any of the signals are non-existant.
// UNAUTHENTICATED if no credentials provided or credentials has expired
// PERMISSION_DENIED if access is denied for any of the signals.
// INVALID_ARGUMENT if the request is empty
// INVALID_ARGUMENT if the request is empty or provided path is too long
//
// When subscribing, Databroker shall immediately return the value for all
// subscribed entries.
Expand All @@ -77,6 +82,7 @@ service VAL {
// UNAVAILABLE if there is no provider currently providing the actuator
// DATA_LOSS is there is a internal TransmissionFailure
// INVALID_ARGUMENT
// - if the provided path is not an actuator.
// - if the data type used in the request does not match
// the data type of the addressed signal
// - if the requested value is not accepted,
Expand All @@ -96,6 +102,7 @@ service VAL {
// UNAVAILABLE if there is no provider currently providing an actuator
// DATA_LOSS is there is a internal TransmissionFailure
// INVALID_ARGUMENT
// - if any of the provided path is not an actuator.
// - if the data type used in the request does not match
// the data type of the addressed signal
// - if the requested value is not accepted,
Expand Down