summaryrefslogtreecommitdiffstats
path: root/crates/common/tedge_config/src/models
diff options
context:
space:
mode:
authorLukasz Woznicki <lukasz.woznicki@softwareag.com>2022-05-13 12:57:01 +0100
committerLukasz Woznicki <lukasz.woznicki@softwareag.com>2022-05-17 11:40:36 +0100
commitf71bb3194f045110d1b5c41491caae5536a73e50 (patch)
tree00805de5a4f8d0e0b58db449f7be3b2813b9cb98 /crates/common/tedge_config/src/models
parent22e874ef463b94c7bc8d0fa892d0ce3a55cbc3c7 (diff)
Add smartrest templates to the list of topics for the bridge creation
Signed-off-by: Lukasz Woznicki <lukasz.woznicki@softwareag.com>
Diffstat (limited to 'crates/common/tedge_config/src/models')
-rw-r--r--crates/common/tedge_config/src/models/templates_set.rs54
1 files changed, 5 insertions, 49 deletions
diff --git a/crates/common/tedge_config/src/models/templates_set.rs b/crates/common/tedge_config/src/models/templates_set.rs
index db47fc8f..da9d32f6 100644
--- a/crates/common/tedge_config/src/models/templates_set.rs
+++ b/crates/common/tedge_config/src/models/templates_set.rs
@@ -8,27 +8,14 @@ use std::convert::TryInto;
pub struct TemplatesSet(pub Vec<String>);
#[derive(thiserror::Error, Debug)]
-#[error("FilePath to String conversion failed: {0:?}")]
+#[error("TemplateSet to String conversion failed: {0:?}")]
pub struct TemplatesSetToStringConversionFailure(String);
impl TryFrom<Vec<String>> for TemplatesSet {
type Error = TemplatesSetToStringConversionFailure;
fn try_from(value: Vec<String>) -> Result<Self, Self::Error> {
- let set = value
- .iter()
- .flat_map(|s| {
- // Smartrest templates should be deserialized as:
- // c8y/s/uc/template-1 (in from localhost), s/uc/template-1
- // c8y/s/dc/template-1 (out to localhost), s/dc/template-1
- [
- format!(r#"c8y/s/uc/{s} out 2 c8y/ """#),
- format!(r#"c8y/s/dc/{s} in 2 c8y/ """#),
- ]
- .into_iter()
- })
- .collect::<Vec<String>>();
- Ok(TemplatesSet(set))
+ Ok(TemplatesSet(value))
}
}
@@ -36,20 +23,9 @@ impl TryFrom<Vec<&str>> for TemplatesSet {
type Error = TemplatesSetToStringConversionFailure;
fn try_from(value: Vec<&str>) -> Result<Self, Self::Error> {
- let set = value
- .iter()
- .flat_map(|s| {
- // Smartrest templates should be deserialized as:
- // c8y/s/uc/template-1 (in from localhost), s/uc/template-1
- // c8y/s/dc/template-1 (out to localhost), s/dc/template-1
- [
- format!(r#"c8y/s/uc/{s} out 2 c8y/ """#),
- format!(r#"c8y/s/dc/{s} in 2 c8y/ """#),
- ]
- .into_iter()
- })
- .collect::<Vec<String>>();
- Ok(TemplatesSet(set))
+ Ok(TemplatesSet(
+ value.into_iter().map(|s| s.into()).collect::<Vec<String>>(),
+ ))
}
}
@@ -79,23 +55,3 @@ impl std::fmt::Display for TemplatesSet {
write!(f, "{:?}", self.0)
}
}
-
-#[cfg(test)]
-mod test {
- use super::TemplatesSet;
-
- #[test]
- fn conversion_from_strings() {
- let strings = vec!["template-1", "template-2"];
- let expected = vec![
- r#"c8y/s/uc/template-1 out 2 c8y/ """#,
- r#"c8y/s/dc/template-1 in 2 c8y/ """#,
- r#"c8y/s/uc/template-2 out 2 c8y/ """#,
- r#"c8y/s/dc/template-2 in 2 c8y/ """#,
- ];
-
- let res = TemplatesSet::try_from(strings).unwrap();
-
- assert_eq!(res.0, expected);
- }
-}