Skip to content

Commit b8d0e03

Browse files
committed
Deprecate TEdgeConfig::try_new_sync
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
1 parent 9b87ef6 commit b8d0e03

File tree

4 files changed

+18
-20
lines changed

4 files changed

+18
-20
lines changed

crates/common/tedge_config/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ impl TEdgeConfig {
2323
config_location.load().await
2424
}
2525

26-
pub fn try_new_sync(config_location: TEdgeConfigLocation) -> Result<Self, TEdgeConfigError> {
27-
config_location.load_sync()
28-
}
29-
3026
pub async fn load(config_dir: &Path) -> Result<TEdgeConfig, TEdgeConfigError> {
3127
let config_location = TEdgeConfigLocation::from_custom_root(config_dir);
3228
TEdgeConfig::try_new(config_location).await

crates/core/tedge/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ async fn main() -> anyhow::Result<()> {
6161
.context("failed to run tedge write process")?
6262
}
6363
TEdgeOptMulticall::Component(Component::TedgeAptPlugin(opt)) => {
64-
tokio::task::spawn_blocking(move || tedge_apt_plugin::run_and_exit(opt))
64+
let config = tedge_apt_plugin::get_config(opt.common.config_dir.as_std_path()).await;
65+
tokio::task::spawn_blocking(move || tedge_apt_plugin::run_and_exit(opt, config))
6566
.await
6667
.context("failed to run tedge apt plugin")?
6768
}

crates/extensions/tedge_mqtt_bridge/src/config.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ mod tests {
235235
use tedge_config::TEdgeConfig;
236236
use tedge_config::TEdgeConfigLocation;
237237

238-
#[test]
239-
fn sets_certs_in_the_provided_mqtt_config() {
238+
#[tokio::test]
239+
async fn sets_certs_in_the_provided_mqtt_config() {
240240
let mut opts = MqttOptions::new("dummy-device", "127.0.0.1", 1883);
241241
let device_cert = rcgen::generate_simple_self_signed(["dummy-device".into()]).unwrap();
242242
let c8y_cert = rcgen::generate_simple_self_signed(["dummy-c8y".into()]).unwrap();
@@ -259,7 +259,8 @@ mod tests {
259259
std::fs::create_dir(root_cert_path.parent().unwrap()).unwrap();
260260
std::fs::write(&root_cert_path, c8y_cert.serialize_pem().unwrap()).unwrap();
261261
let tedge_config =
262-
TEdgeConfig::try_new_sync(TEdgeConfigLocation::from_custom_root(ttd.path()))
262+
TEdgeConfig::try_new(TEdgeConfigLocation::from_custom_root(ttd.path()))
263+
.await
263264
.unwrap();
264265
let c8y_config = tedge_config.c8y.try_get::<str>(None).unwrap();
265266

plugins/tedge_apt_plugin/src/lib.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use tracing::warn;
2727
)]
2828
pub struct AptCli {
2929
#[command(flatten)]
30-
common: CommonArgs,
30+
pub common: CommonArgs,
3131

3232
#[clap(subcommand)]
3333
operation: PluginOp,
@@ -88,7 +88,7 @@ struct SoftwareModuleUpdate {
8888
pub path: Option<String>,
8989
}
9090

91-
fn run_op(apt: AptCli) -> Result<ExitStatus, InternalError> {
91+
fn run_op(apt: AptCli, tedge_config: Option<TEdgeConfig>) -> Result<ExitStatus, InternalError> {
9292
if let Err(err) = log_init(
9393
"tedge-apt-plugin",
9494
&apt.common.log_args,
@@ -147,7 +147,7 @@ fn run_op(apt: AptCli) -> Result<ExitStatus, InternalError> {
147147
file_path,
148148
} => {
149149
let (installer, _metadata) = get_installer(module, version, file_path)?;
150-
let dpk_option = get_dpk_option(apt.common.config_dir.as_std_path());
150+
let dpk_option = get_dpk_option(&tedge_config);
151151
AptGetCmd::Install(dpk_option, vec![installer]).run()?
152152
}
153153

@@ -173,7 +173,7 @@ fn run_op(apt: AptCli) -> Result<ExitStatus, InternalError> {
173173
// which will get cleaned up once it goes out of scope after this block
174174
let mut metadata_vec = Vec::new();
175175
let mut args: Vec<String> = Vec::new();
176-
let dpk_option = get_dpk_option(apt.common.config_dir.as_std_path());
176+
let dpk_option = get_dpk_option(&tedge_config);
177177

178178
for update_module in updates {
179179
match update_module.action {
@@ -319,8 +319,8 @@ impl AptGetCmd {
319319
}
320320
}
321321

322-
fn get_dpk_option(config_dir: &Path) -> AptConfig {
323-
match get_config(config_dir) {
322+
fn get_dpk_option(tedge_config: &Option<TEdgeConfig>) -> AptConfig {
323+
match tedge_config {
324324
None => AptConfig::KeepNew,
325325
Some(config) => config.apt.dpk.options.config.clone(),
326326
}
@@ -334,10 +334,10 @@ fn get_name_and_version(line: &str) -> (&str, &str) {
334334
(name, version)
335335
}
336336

337-
fn get_config(config_dir: &Path) -> Option<TEdgeConfig> {
337+
pub async fn get_config(config_dir: &Path) -> Option<TEdgeConfig> {
338338
let tedge_config_location = TEdgeConfigLocation::from_custom_root(config_dir);
339339

340-
match TEdgeConfig::try_new_sync(tedge_config_location) {
340+
match TEdgeConfig::try_new(tedge_config_location).await {
341341
Ok(config) => Some(config),
342342
Err(err) => {
343343
warn!("Failed to load TEdgeConfig: {}", err);
@@ -346,9 +346,9 @@ fn get_config(config_dir: &Path) -> Option<TEdgeConfig> {
346346
}
347347
}
348348

349-
pub fn run_and_exit(mut apt: AptCli) -> ! {
349+
pub fn run_and_exit(mut apt: AptCli, tedge_config: Option<TEdgeConfig>) -> ! {
350350
if let PluginOp::List { name, maintainer } = &mut apt.operation {
351-
if let Some(config) = get_config(apt.common.config_dir.as_std_path()) {
351+
if let Some(config) = &tedge_config {
352352
if name.is_none() {
353353
*name = config.apt.name.or_none().cloned();
354354
}
@@ -359,7 +359,7 @@ pub fn run_and_exit(mut apt: AptCli) -> ! {
359359
}
360360
}
361361

362-
match run_op(apt) {
362+
match run_op(apt, tedge_config) {
363363
Ok(status) if status.success() => {
364364
std::process::exit(0);
365365
}
@@ -414,6 +414,6 @@ mod tests {
414414
config_dir: "".into(),
415415
},
416416
};
417-
assert!(run_op(apt).is_ok())
417+
assert!(run_op(apt, None).is_ok())
418418
}
419419
}

0 commit comments

Comments
 (0)