From d46f8f4d14b15e35a219f7369f7a0facc1e1fee3 Mon Sep 17 00:00:00 2001 From: Reuben Miller Date: Fri, 3 May 2024 08:57:02 +0200 Subject: [PATCH] support reading child connection string from stdin Improves compatibility with other components such as systemd sockets where the socket data is feed via stdin Signed-off-by: Reuben Miller --- plugins/c8y_remote_access_plugin/src/input.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/c8y_remote_access_plugin/src/input.rs b/plugins/c8y_remote_access_plugin/src/input.rs index 082cb5d7445..5084f5725aa 100644 --- a/plugins/c8y_remote_access_plugin/src/input.rs +++ b/plugins/c8y_remote_access_plugin/src/input.rs @@ -4,6 +4,7 @@ use miette::ensure; use miette::miette; use miette::Context; use serde::Deserialize; +use std::io::BufRead; use std::path::PathBuf; use tedge_config::TEdgeConfigLocation; use tedge_config::DEFAULT_TEDGE_CONFIG_PATH; @@ -44,6 +45,7 @@ pub struct C8yRemoteAccessPluginOpt { connect_string: Option, #[arg(long)] + // Use "-" to read the value from stdin. child: Option, } @@ -88,7 +90,17 @@ impl TryFrom for Command { impl RemoteAccessConnect { fn deserialize_smartrest(message: &str) -> miette::Result { - let (id, command): (u16, Self) = deserialize_csv_record(message) + // Read value from stdin + let message = if message.eq("-") { + let mut line = String::new(); + let stdin = std::io::stdin(); + stdin.lock().read_line(&mut line).unwrap(); + line.to_string() + } else { + message.to_string() + }; + + let (id, command): (u16, Self) = deserialize_csv_record(message.as_str()) .context("Deserialising arguments of remote access connect message")?; ensure!( id == 530,