Skip to content

Commit

Permalink
support reading child connection string from stdin
Browse files Browse the repository at this point in the history
Improves compatibility with other components such as systemd sockets where the socket data is feed via stdin

Signed-off-by: Reuben Miller <[email protected]>
  • Loading branch information
reubenmiller committed May 13, 2024
1 parent 9b1698d commit d46f8f4
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion plugins/c8y_remote_access_plugin/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,6 +45,7 @@ pub struct C8yRemoteAccessPluginOpt {
connect_string: Option<String>,

#[arg(long)]
// Use "-" to read the value from stdin.
child: Option<String>,
}

Expand Down Expand Up @@ -88,7 +90,17 @@ impl TryFrom<C8yRemoteAccessPluginOpt> for Command {

impl RemoteAccessConnect {
fn deserialize_smartrest(message: &str) -> miette::Result<Self> {
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,
Expand Down

0 comments on commit d46f8f4

Please sign in to comment.