diff options
author | Lukasz Woznicki <75632179+makr11st@users.noreply.github.com> | 2021-12-07 21:42:25 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-07 21:42:25 +0000 |
commit | c2d8195b6a779752ae16628fa0a06d040066bc1c (patch) | |
tree | a6001216a3652ae149d0c1ae244712e317a792d1 /crates/core/c8y_smartrest | |
parent | 13c6cd0195bbcf0ebc917d02d8dea4bf744635a7 (diff) |
#596 Declare supported operations (#652)
* Add operations to tedge_mapper
* Add operations directory on install, remove supported ops from sm-c8y mapper
* Update install command in postinst script to correctly create ops files
Signed-off-by: Lukasz Woznicki <lukasz.woznicki@softwareag.com>
Diffstat (limited to 'crates/core/c8y_smartrest')
-rw-r--r-- | crates/core/c8y_smartrest/src/smartrest_serializer.rs | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/crates/core/c8y_smartrest/src/smartrest_serializer.rs b/crates/core/c8y_smartrest/src/smartrest_serializer.rs index ce48c1a3..e7934d7f 100644 --- a/crates/core/c8y_smartrest/src/smartrest_serializer.rs +++ b/crates/core/c8y_smartrest/src/smartrest_serializer.rs @@ -41,7 +41,7 @@ impl Default for SmartRestSetSupportedLogType { fn default() -> Self { Self { message_id: "118", - supported_operations: vec!["software-management".into()], + supported_operations: vec!["software-management"], } } } @@ -49,25 +49,25 @@ impl Default for SmartRestSetSupportedLogType { impl<'a> SmartRestSerializer<'a> for SmartRestSetSupportedLogType {} #[derive(Debug, Deserialize, Serialize, PartialEq)] -pub struct SmartRestSetSupportedOperations { +pub struct SmartRestSetSupportedOperations<'a> { pub message_id: &'static str, - pub supported_operations: Vec<&'static str>, + pub supported_operations: Vec<&'a str>, } -impl Default for SmartRestSetSupportedOperations { - fn default() -> Self { +impl<'a> SmartRestSetSupportedOperations<'a> { + pub fn new(supported_operations: &[&'a str]) -> Self { Self { message_id: "114", - supported_operations: vec![ - CumulocitySupportedOperations::C8ySoftwareUpdate.into(), - CumulocitySupportedOperations::C8yLogFileRequest.into(), - CumulocitySupportedOperations::C8yRestartRequest.into(), - ], + supported_operations: supported_operations.into(), } } + + pub fn add_operation(&mut self, operation: &'a str) { + self.supported_operations.push(operation); + } } -impl<'a> SmartRestSerializer<'a> for SmartRestSetSupportedOperations {} +impl<'a> SmartRestSerializer<'a> for SmartRestSetSupportedOperations<'a> {} #[derive(Debug, Deserialize, Serialize, PartialEq)] pub struct SmartRestSoftwareModuleItem { @@ -211,15 +211,12 @@ mod tests { use json_sm::*; #[test] - // NOTE: this test always needs changing when a new operation is added fn serialize_smartrest_supported_operations() { - let smartrest = SmartRestSetSupportedOperations::default() - .to_smartrest() - .unwrap(); - assert_eq!( - smartrest, - "114,c8y_SoftwareUpdate,c8y_LogfileRequest,c8y_Restart\n" - ); + let smartrest = + SmartRestSetSupportedOperations::new(&["c8y_SoftwareUpdate", "c8y_LogfileRequest"]) + .to_smartrest() + .unwrap(); + assert_eq!(smartrest, "114,c8y_SoftwareUpdate,c8y_LogfileRequest\n"); } #[test] |