Skip to content

Commit a6db6bc

Browse files
committed
Apply more review suggestions
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
1 parent 335ac91 commit a6db6bc

File tree

13 files changed

+169
-74
lines changed

13 files changed

+169
-74
lines changed

Cargo.lock

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/common/tedge_config/src/tedge_config_cli/tedge_config.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ define_tedge_config! {
455455

456456
#[tedge_config(default(value = false))]
457457
#[doku(skip)] // Hide the configuration in `tedge config list --doc`
458-
in_mapper: bool,
458+
built_in: bool,
459459

460460
// TODO validation
461461
/// The topic prefix that will be used for the mapper bridge MQTT topic. For instance,
@@ -818,10 +818,15 @@ define_tedge_config! {
818818
}
819819

820820
impl ReadableKey {
821-
// This is designed to be simple way of
821+
// This is designed to be a simple way of controlling whether values appear in the output of
822+
// `tedge config list`. Ideally this would be integrated into [define_tedge_config], see
823+
// https://github.com/thin-edge/thin-edge.io/issues/2767 for more detail on that.
824+
// Currently this accompanies `#[doku(skip)]` on the relevant configurations, which hides
825+
// them in `tedge config list --doc`. The configurations are hidden to avoid unfinished
826+
// features from being discovered.
822827
pub fn is_printable_value(self, value: &str) -> bool {
823828
match self {
824-
Self::C8yBridgeInMapper => value != "false",
829+
Self::C8yBridgeBuiltIn => value != "false",
825830
Self::C8yBridgeTopicPrefix => value != "c8y",
826831
_ => true,
827832
}

crates/core/c8y_api/src/utils.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
pub mod bridge {
22
use mqtt_channel::Message;
3-
4-
// FIXME: doesn't account for custom topic root, use MQTT scheme API here
5-
pub const C8Y_BRIDGE_UP_PAYLOAD: &str = "1";
6-
pub const C8Y_BRIDGE_DOWN_PAYLOAD: &str = "0";
7-
8-
pub fn main_device_health_topic(service: &str) -> String {
9-
format!("te/device/main/service/{service}/status/health")
10-
}
3+
use tedge_api::main_device_health_topic;
4+
use tedge_api::MQTT_BRIDGE_DOWN_PAYLOAD;
5+
use tedge_api::MQTT_BRIDGE_UP_PAYLOAD;
116

127
pub fn is_c8y_bridge_up(message: &Message, service: &str) -> bool {
138
let c8y_bridge_health_topic = main_device_health_topic(service);
149
match message.payload_str() {
1510
Ok(payload) => {
16-
message.topic.name == c8y_bridge_health_topic && payload == C8Y_BRIDGE_UP_PAYLOAD
11+
message.topic.name == c8y_bridge_health_topic && payload == MQTT_BRIDGE_UP_PAYLOAD
1712
}
1813
Err(_err) => false,
1914
}
@@ -24,7 +19,7 @@ pub mod bridge {
2419
match message.payload_str() {
2520
Ok(payload) => {
2621
message.topic.name == c8y_bridge_health_topic
27-
&& (payload == C8Y_BRIDGE_UP_PAYLOAD || payload == C8Y_BRIDGE_DOWN_PAYLOAD)
22+
&& (payload == MQTT_BRIDGE_UP_PAYLOAD || payload == MQTT_BRIDGE_DOWN_PAYLOAD)
2823
}
2924
Err(_err) => false,
3025
}

crates/core/tedge/src/bridge/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub struct BridgeConfig {
3838
#[derive(Debug, Eq, PartialEq, Clone, Copy)]
3939
pub enum BridgeLocation {
4040
Mosquitto,
41-
Mapper,
41+
BuiltIn,
4242
}
4343

4444
impl BridgeConfig {

crates/core/tedge/src/cli/connect/command.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ pub fn bridge_config(
197197
Ok(BridgeConfig::from(params))
198198
}
199199
Cloud::C8y => {
200-
let bridge_location = match config.c8y.bridge.in_mapper {
201-
true => BridgeLocation::Mapper,
200+
let bridge_location = match config.c8y.bridge.built_in {
201+
true => BridgeLocation::BuiltIn,
202202
false => BridgeLocation::Mosquitto,
203203
};
204204
let params = BridgeConfigC8yParams {
@@ -440,7 +440,7 @@ fn new_bridge(
440440
config_location: &TEdgeConfigLocation,
441441
device_type: &str,
442442
) -> Result<(), ConnectError> {
443-
if bridge_config.bridge_location == BridgeLocation::Mapper {
443+
if bridge_config.bridge_location == BridgeLocation::BuiltIn {
444444
clean_up(config_location, bridge_config)?;
445445
return Ok(());
446446
}

crates/core/tedge_api/src/health.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ use std::process;
1111
use std::sync::Arc;
1212
use tedge_utils::timestamp::TimeFormat;
1313

14+
pub const MQTT_BRIDGE_UP_PAYLOAD: &str = "1";
15+
pub const MQTT_BRIDGE_DOWN_PAYLOAD: &str = "0";
16+
17+
// FIXME: doesn't account for custom topic root, use MQTT scheme API here
18+
pub fn main_device_health_topic(service: &str) -> String {
19+
format!("te/device/main/service/{service}/status/health")
20+
}
21+
1422
/// Encodes a valid health topic.
1523
///
1624
/// Health topics are topics on which messages about health status of services are published. To be

crates/core/tedge_api/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub mod workflow;
2323
pub use download::*;
2424
pub use entity_store::EntityStore;
2525
pub use error::*;
26+
pub use health::*;
2627
pub use messages::CommandStatus;
2728
pub use messages::Jsonify;
2829
pub use messages::OperationStatus;

crates/core/tedge_mapper/src/c8y/mapper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl TEdgeComponent for CumulocityMapper {
3838

3939
let mqtt_config = tedge_config.mqtt_config()?;
4040
let c8y_mapper_config = C8yMapperConfig::from_tedge_config(cfg_dir, &tedge_config)?;
41-
if tedge_config.c8y.bridge.in_mapper {
41+
if tedge_config.c8y.bridge.built_in {
4242
let custom_topics = tedge_config
4343
.c8y
4444
.smartrest

crates/extensions/c8y_mapper_ext/src/actor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use c8y_api::smartrest::smartrest_serializer::succeed_static_operation;
88
use c8y_api::smartrest::smartrest_serializer::CumulocitySupportedOperations;
99
use c8y_api::smartrest::smartrest_serializer::SmartRest;
1010
use c8y_api::utils::bridge::is_c8y_bridge_established;
11-
use c8y_api::utils::bridge::main_device_health_topic;
1211
use c8y_auth_proxy::url::ProxyUrlGenerator;
1312
use c8y_http_proxy::handle::C8YHttpProxy;
1413
use c8y_http_proxy::messages::C8YRestRequest;
@@ -33,6 +32,7 @@ use tedge_actors::Service;
3332
use tedge_actors::ServiceProvider;
3433
use tedge_actors::SimpleMessageBox;
3534
use tedge_actors::SimpleMessageBoxBuilder;
35+
use tedge_api::main_device_health_topic;
3636
use tedge_downloader_ext::DownloadRequest;
3737
use tedge_downloader_ext::DownloadResult;
3838
use tedge_file_system_ext::FsWatchEvent;

crates/extensions/c8y_mapper_ext/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl C8yMapperConfig {
197197
}
198198
}
199199

200-
let bridge_in_mapper = tedge_config.c8y.bridge.in_mapper;
200+
let bridge_in_mapper = tedge_config.c8y.bridge.built_in;
201201

202202
Ok(C8yMapperConfig::new(
203203
config_dir,

0 commit comments

Comments
 (0)