Accept file payloads for pipe send

This commit is contained in:
Eric Wendland 2026-05-20 13:59:41 +02:00
commit 55cb455de3
5 changed files with 34 additions and 11 deletions

View file

@ -4,6 +4,7 @@ use clap::{Args, Parser, Subcommand};
use geth_config::GethPaths;
use geth_control::{ControlRequest, ControlResponse};
use geth_node::service::{ServiceInstallOptions, ServiceManager, ServiceReport};
use std::io::Read;
use std::path::PathBuf;
#[derive(Debug, Parser)]
@ -398,7 +399,9 @@ pub enum PipeCommand {
},
Send {
target: String,
message: String,
message: Option<String>,
#[arg(long = "in", value_name = "PATH")]
input: Option<PathBuf>,
#[arg(long)]
node: Option<String>,
#[arg(long)]
@ -880,11 +883,12 @@ fn request_for_command(command: Command) -> Result<ControlRequest> {
PipeCommand::Send {
target,
message,
input,
node,
bearer_secret,
} => ControlRequest::PipeSend {
target,
data_base64: base64::engine::general_purpose::STANDARD.encode(message.as_bytes()),
data_base64: pipe_send_payload_base64(message, input)?,
node,
bearer_secret,
},
@ -2140,6 +2144,25 @@ fn print_pipe_message_data(message: &geth_pipe::PipeMessage) -> Result<()> {
Ok(())
}
fn pipe_send_payload_base64(message: Option<String>, input: Option<PathBuf>) -> Result<String> {
match (message, input) {
(Some(message), None) => Ok(base64::engine::general_purpose::STANDARD.encode(message)),
(None, Some(path)) if path.as_os_str() == "-" => {
let mut bytes = Vec::new();
std::io::stdin()
.read_to_end(&mut bytes)
.context("read pipe payload from stdin")?;
Ok(base64::engine::general_purpose::STANDARD.encode(bytes))
}
(None, Some(path)) => {
let bytes = std::fs::read(&path).with_context(|| format!("read {}", path.display()))?;
Ok(base64::engine::general_purpose::STANDARD.encode(bytes))
}
(Some(_), Some(_)) => bail!("pipe send accepts either MESSAGE or --in, not both"),
(None, None) => bail!("pipe send requires MESSAGE or --in <path>; use --in - for stdin"),
}
}
fn shell_quote_command(command: &[String]) -> String {
command
.iter()