Skip to content

Commit

Permalink
Remove unsafe unwrap
Browse files Browse the repository at this point in the history
A topic filter cannot be safely cast into a topic.

Signed-off-by: Didier Wenzek <[email protected]>
  • Loading branch information
didier-wenzek committed May 17, 2024
1 parent 7658186 commit c8bd36b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions crates/common/mqtt_channel/src/topics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ impl Topic {
/// An MQTT topic filter
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct TopicFilter {
pub patterns: Vec<String>,
pub qos: QoS,
patterns: Vec<String>,
qos: QoS,
}

impl Default for TopicFilter {
Expand Down
4 changes: 2 additions & 2 deletions crates/extensions/tedge_config_manager/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,9 @@ impl ConfigManagerActor {
async fn publish_supported_config_types(&mut self) -> Result<(), ChannelError> {
let mut config_types = self.plugin_config.get_all_file_types();
config_types.sort();
for topic in self.config.config_reload_topics.patterns.iter() {
for topic in self.config.config_reload_topics.iter() {
let metadata = ConfigOperationData::Metadata {
topic: Topic::new_unchecked(topic),
topic: topic.clone(),
types: config_types.clone(),
};
self.mqtt_publisher.send(metadata.into()).await?;
Expand Down
10 changes: 3 additions & 7 deletions crates/extensions/tedge_config_manager/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use tedge_api::mqtt_topics::MqttSchema;
use tedge_api::mqtt_topics::OperationType;
use tedge_config::ReadError;
use tedge_config::SudoCommandBuilder;
use tedge_mqtt_ext::Topic;
use tedge_mqtt_ext::TopicFilter;
use tedge_utils::file::PermissionEntry;

Expand All @@ -35,7 +36,7 @@ pub struct ConfigManagerConfig {
pub plugin_config_path: PathBuf,
pub tmp_path: Arc<Utf8Path>,
pub mqtt_schema: MqttSchema,
pub config_reload_topics: TopicFilter,
pub config_reload_topics: Vec<Topic>,
pub config_update_topic: TopicFilter,
pub config_snapshot_topic: TopicFilter,
pub tedge_http_host: Arc<str>,
Expand Down Expand Up @@ -66,12 +67,7 @@ impl ConfigManagerConfig {

let config_reload_topics = [OperationType::ConfigSnapshot, OperationType::ConfigUpdate]
.into_iter()
.map(|cmd| {
mqtt_topic_root.topics(
EntityFilter::Entity(&mqtt_device_topic_id),
ChannelFilter::CommandMetadata(cmd),
)
})
.map(|cmd| mqtt_topic_root.capability_topic_for(&mqtt_device_topic_id, cmd))
.collect();

let config_update_topic = mqtt_topic_root.topics(
Expand Down
7 changes: 4 additions & 3 deletions crates/extensions/tedge_config_manager/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ async fn new_config_manager_builder(
config_dir: temp_dir.to_path_buf(),
plugin_config_dir: temp_dir.to_path_buf(),
plugin_config_path: temp_dir.join("tedge-configuration-plugin.toml"),
config_reload_topics: vec![
config_reload_topics: [
"te/device/main///cmd/config_snapshot",
"te/device/main///cmd/config_update",
]
.try_into()
.expect("Infallible"),
.into_iter()
.map(Topic::new_unchecked)
.collect(),
tmp_path: Arc::from(Utf8Path::from_path(&std::env::temp_dir()).unwrap()),
use_tedge_write: TedgeWriteStatus::Disabled,
mqtt_schema: MqttSchema::new(),
Expand Down

0 comments on commit c8bd36b

Please sign in to comment.