diff options
author | Lukasz Woznicki <lukasz.woznicki@softwareag.com> | 2022-05-13 12:57:01 +0100 |
---|---|---|
committer | Lukasz Woznicki <lukasz.woznicki@softwareag.com> | 2022-05-17 11:40:36 +0100 |
commit | f71bb3194f045110d1b5c41491caae5536a73e50 (patch) | |
tree | 00805de5a4f8d0e0b58db449f7be3b2813b9cb98 /crates/core | |
parent | 22e874ef463b94c7bc8d0fa892d0ce3a55cbc3c7 (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/core')
-rw-r--r-- | crates/core/tedge/src/cli/config/config_key.rs | 1 | ||||
-rw-r--r-- | crates/core/tedge/src/cli/connect/bridge_config_c8y.rs | 90 | ||||
-rw-r--r-- | crates/core/tedge/src/cli/connect/command.rs | 1 |
3 files changed, 61 insertions, 31 deletions
diff --git a/crates/core/tedge/src/cli/config/config_key.rs b/crates/core/tedge/src/cli/config/config_key.rs index 96227269..161f0e4c 100644 --- a/crates/core/tedge/src/cli/config/config_key.rs +++ b/crates/core/tedge/src/cli/config/config_key.rs @@ -45,6 +45,7 @@ impl ConfigKey { config_key!(DeviceCertPathSetting), config_key!(C8yUrlSetting), config_key!(C8yRootCertPathSetting), + config_key!(C8ySmartRestTemplates), config_key!(AzureUrlSetting), config_key!(AzureRootCertPathSetting), config_key!(AzureMapperTimestamp), diff --git a/crates/core/tedge/src/cli/connect/bridge_config_c8y.rs b/crates/core/tedge/src/cli/connect/bridge_config_c8y.rs index 90fdab7e..31330598 100644 --- a/crates/core/tedge/src/cli/connect/bridge_config_c8y.rs +++ b/crates/core/tedge/src/cli/connect/bridge_config_c8y.rs @@ -1,5 +1,5 @@ use crate::cli::connect::BridgeConfig; -use tedge_config::{ConnectUrl, FilePath}; +use tedge_config::{ConnectUrl, FilePath, TemplatesSet}; #[derive(Debug, PartialEq)] pub struct BridgeConfigC8yParams { @@ -10,6 +10,7 @@ pub struct BridgeConfigC8yParams { pub bridge_root_cert_path: FilePath, pub bridge_certfile: FilePath, pub bridge_keyfile: FilePath, + pub smartrest_templates: TemplatesSet, } impl From<BridgeConfigC8yParams> for BridgeConfig { @@ -22,9 +23,57 @@ impl From<BridgeConfigC8yParams> for BridgeConfig { remote_clientid, bridge_certfile, bridge_keyfile, + smartrest_templates, } = params; let address = format!("{}:{}", connect_url.as_str(), mqtt_tls_port); + let mut topics: Vec<String> = vec![ + // Registration + r#"s/dcr in 2 c8y/ """#.into(), + r#"s/ucr out 2 c8y/ """#.into(), + // Templates + r#"s/dt in 2 c8y/ """#.into(), + r#"s/ut/# out 2 c8y/ """#.into(), + // Static templates + r#"s/us/# out 2 c8y/ """#.into(), + r#"t/us/# out 2 c8y/ """#.into(), + r#"q/us/# out 2 c8y/ """#.into(), + r#"c/us/# out 2 c8y/ """#.into(), + r#"s/ds in 2 c8y/ """#.into(), + // Debug + r#"s/e in 0 c8y/ """#.into(), + // SmartRest2 + r#"s/uc/# out 2 c8y/ """#.into(), + r#"t/uc/# out 2 c8y/ """#.into(), + r#"q/uc/# out 2 c8y/ """#.into(), + r#"c/uc/# out 2 c8y/ """#.into(), + r#"s/dc/# in 2 c8y/ """#.into(), + // c8y JSON + r#"inventory/managedObjects/update/# out 2 c8y/ """#.into(), + r#"measurement/measurements/create out 2 c8y/ """#.into(), + r#"event/events/create out 2 c8y/ """#.into(), + r#"error in 2 c8y/ """#.into(), + // c8y JWT token retrieval + r#"s/uat/# out 2 c8y/ """#.into(), + r#"s/dat/# in 2 c8y/ """#.into(), + ]; + + let templates_set = smartrest_templates + .0 + .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#"s/uc/{s} out 2 c8y/ """#), + format!(r#"s/dc/{s} in 2 c8y/ """#), + ] + .into_iter() + }) + .collect::<Vec<String>>(); + topics.extend(templates_set); + Self { cloud_name: "c8y".into(), config_file, @@ -45,36 +94,7 @@ impl From<BridgeConfigC8yParams> for BridgeConfig { notifications_local_only: true, notification_topic: "tedge/health/mosquitto-c8y-bridge".into(), bridge_attempt_unsubscribe: false, - topics: vec![ - // Registration - r#"s/dcr in 2 c8y/ """#.into(), - r#"s/ucr out 2 c8y/ """#.into(), - // Templates - r#"s/dt in 2 c8y/ """#.into(), - r#"s/ut/# out 2 c8y/ """#.into(), - // Static templates - r#"s/us/# out 2 c8y/ """#.into(), - r#"t/us/# out 2 c8y/ """#.into(), - r#"q/us/# out 2 c8y/ """#.into(), - r#"c/us/# out 2 c8y/ """#.into(), - r#"s/ds in 2 c8y/ """#.into(), - // Debug - r#"s/e in 0 c8y/ """#.into(), - // SmartRest2 - r#"s/uc/# out 2 c8y/ """#.into(), - r#"t/uc/# out 2 c8y/ """#.into(), - r#"q/uc/# out 2 c8y/ """#.into(), - r#"c/uc/# out 2 c8y/ """#.into(), - r#"s/dc/# in 2 c8y/ """#.into(), - // c8y JSON - r#"inventory/managedObjects/update/# out 2 c8y/ """#.into(), - r#"measurement/measurements/create out 2 c8y/ """#.into(), - r#"event/events/create out 2 c8y/ """#.into(), - r#"error in 2 c8y/ """#.into(), - // c8y JWT token retrieval - r#"s/uat/# out 2 c8y/ """#.into(), - r#"s/dat/# in 2 c8y/ """#.into(), - ], + topics, } } } @@ -90,6 +110,7 @@ fn test_bridge_config_from_c8y_params() -> anyhow::Result<()> { bridge_root_cert_path: "./test_root.pem".into(), bridge_certfile: "./test-certificate.pem".into(), bridge_keyfile: "./test-private-key.pem".into(), + smartrest_templates: TemplatesSet::try_from(vec!["abc", "def"])?, }; let bridge = BridgeConfig::from(params); @@ -136,6 +157,13 @@ fn test_bridge_config_from_c8y_params() -> anyhow::Result<()> { // c8y JWT token retrieval r#"s/uat/# out 2 c8y/ """#.into(), r#"s/dat/# in 2 c8y/ """#.into(), + // Smartrest templates should be deserialized as: + // s/uc/template-1 (in from localhost), s/uc/template-1 + // s/dc/template-1 (out to localhost), s/dc/template-1 + r#"s/uc/abc out 2 c8y/ """#.into(), + r#"s/dc/abc in 2 c8y/ """#.into(), + r#"s/uc/def out 2 c8y/ """#.into(), + r#"s/dc/def in 2 c8y/ """#.into(), ], try_private: false, start_type: "automatic".into(), diff --git a/crates/core/tedge/src/cli/connect/command.rs b/crates/core/tedge/src/cli/connect/command.rs index 30682ddd..7da926d0 100644 --- a/crates/core/tedge/src/cli/connect/command.rs +++ b/crates/core/tedge/src/cli/connect/command.rs @@ -203,6 +203,7 @@ impl ConnectCommand { remote_clientid: config.query(DeviceIdSetting)?, bridge_certfile: config.query(DeviceCertPathSetting)?, bridge_keyfile: config.query(DeviceKeyPathSetting)?, + smartrest_templates: config.query(C8ySmartRestTemplates)?, }; Ok(BridgeConfig::from(params)) |