Skip to content

Commit

Permalink
Merge pull request thin-edge#3283 from rina23q/fix/3095/accept-third-…
Browse files Browse the repository at this point in the history
…argument-for-503-and-506

Custom operation handler should parse extra arguments for 503/506 messages
  • Loading branch information
rina23q authored Dec 12, 2024
2 parents 7a5dd83 + cf7357a commit 3d77ad5
Show file tree
Hide file tree
Showing 16 changed files with 481 additions and 56 deletions.
4 changes: 4 additions & 0 deletions crates/core/tedge_api/src/mqtt_topics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,10 @@ impl IdGenerator {
.strip_prefix(&self.prefix)
.and_then(|s| s.strip_prefix('-'))
}

pub fn prefix(&self) -> &str {
self.prefix.as_str()
}
}

#[cfg(test)]
Expand Down
3 changes: 2 additions & 1 deletion crates/core/tedge_api/src/workflow/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ const FAILED: &str = "failed";
const REASON: &str = "reason";

impl GenericCommandState {
pub fn new(topic: Topic, status: String, payload: Value) -> Self {
pub fn new(topic: Topic, status: String, mut payload: Value) -> Self {
let invoking_command_topic = Self::infer_invoking_command_topic(topic.as_ref());
Self::inject_text_property(&mut payload, STATUS, &status);
GenericCommandState {
topic,
status,
Expand Down
12 changes: 11 additions & 1 deletion crates/extensions/c8y_mapper_ext/src/operations/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use c8y_api::json_c8y_deserializer::C8yLogfileRequest;
use c8y_api::json_c8y_deserializer::C8yUploadConfigFile;
use c8y_api::smartrest::message_ids::SET_SUPPORTED_CONFIGURATIONS;
use c8y_api::smartrest::message_ids::SET_SUPPORTED_LOGS;
use serde_json::json;
use serde_json::Value;
use std::sync::Arc;
use tedge_api::commands::CommandStatus;
Expand Down Expand Up @@ -433,7 +434,16 @@ impl CumulocityConverter {
serde_json::Value::Object(serde_json::Map::new())
};

let request = GenericCommandState::new(topic, CommandStatus::Init.to_string(), payload);
let mapper_id = self.command_id.prefix();
let inject_object = json!({
mapper_id: {
"on_fragment": custom_handler.on_fragment(),
"output": custom_handler.workflow_output(),
}
});

let request = GenericCommandState::new(topic, CommandStatus::Init.to_string(), payload)
.update_with_json(inject_object);

Ok(vec![request.into_message()])
}
Expand Down
Loading

0 comments on commit 3d77ad5

Please sign in to comment.