Skip to main content

ScriptIo

Trait ScriptIo 

Source
pub trait ScriptIo: Send + Sync {
    // Required methods
    fn http_get(
        &self,
        url: &str,
        headers: BTreeMap<String, String>,
    ) -> Result<String, String>;
    fn http_post(
        &self,
        url: &str,
        body: &str,
        headers: BTreeMap<String, String>,
    ) -> Result<String, String>;
    fn run_shell(
        &self,
        cmd: TokioCommand,
        timeout: Duration,
    ) -> Result<String, String>;
    fn read_file(&self, path: &Path) -> Result<String, String>;
    fn write_file(&self, path: &Path, content: &str) -> Result<String, String>;
    fn env_var(&self, name: &str) -> Result<String, String>;
}
Expand description

The raw I/O a DaemonScriptHost performs, behind a seam so the host’s permission/confinement logic is testable without real side effects.

Required Methods§

Source

fn http_get( &self, url: &str, headers: BTreeMap<String, String>, ) -> Result<String, String>

Perform an HTTP GET, returning the response body (or an error message).

Source

fn http_post( &self, url: &str, body: &str, headers: BTreeMap<String, String>, ) -> Result<String, String>

Perform an HTTP POST, returning the response body (or an error message).

Source

fn run_shell( &self, cmd: TokioCommand, timeout: Duration, ) -> Result<String, String>

Run a prepared shell command (already sandbox-wrapped and pointed at the workdir by the host), enforcing timeout, and return its combined output.

Source

fn read_file(&self, path: &Path) -> Result<String, String>

Read the file at an already-confined absolute path.

Source

fn write_file(&self, path: &Path, content: &str) -> Result<String, String>

Write content to an already-confined absolute path, creating parent directories as needed. Returns a short confirmation.

Source

fn env_var(&self, name: &str) -> Result<String, String>

Read environment variable name.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§