subspace_core/credentials/
runner.rs1use std::time::Duration;
4
5mod process;
6mod request;
7
8use request::{CapturedOutput, RunnerRequest};
9
10pub trait Runner: Send + Sync {
12 fn run(
15 &self,
16 program: &str,
17 args: &[&str],
18 remove: &[&str],
19 timeout: Duration,
20 ) -> Result<String, String>;
21}
22
23pub struct SystemRunner;
24
25impl Runner for SystemRunner {
26 fn run(
27 &self,
28 program: &str,
29 args: &[&str],
30 remove: &[&str],
31 timeout: Duration,
32 ) -> Result<String, String> {
33 let output = process::capture(RunnerRequest::new(program, args, remove, timeout))?;
34 successful_output(program, output)
35 }
36}
37
38fn successful_output(program: &str, output: CapturedOutput) -> Result<String, String> {
39 match output.exit_code {
40 Some(0) => Ok(output.stdout),
41 _ => Err(format!("{program} failed")),
42 }
43}
44
45#[cfg(test)]
46mod tests;