Skip to main content

RemoteShell

Struct RemoteShell 

Source
pub struct RemoteShell { /* private fields */ }
Expand description

How one node’s ssh and sftp invocations are built and run.

Implementations§

Source§

impl RemoteShell

Source

pub fn from_ssh( repo: &Path, target_file: &str, label: &str, ssh: &Ssh, runner: Arc<dyn ProcessRunner>, ) -> Result<RemoteShell, CoreError>

Build the shell for ssh of node label (nodes.master), reading the key from the process environment.

Source

pub fn from_ssh_with_env( repo: &Path, target_file: &str, label: &str, ssh: &Ssh, runner: Arc<dyn ProcessRunner>, env: &dyn Fn(&str) -> Option<String>, ) -> Result<RemoteShell, CoreError>

from_ssh with an injectable environment lookup (tests; avoids mutating the process environment).

Source

pub fn label(&self) -> &str

The node label used in errors (nodes.master).

Source

pub fn op_timeout(&self) -> Duration

The per-call timeout.

Source

pub fn temp_dir(&self) -> Option<&Path>

This shell’s private temp dir (known_hosts copy and key).

Source

pub fn known_hosts_copy(&self) -> &Path

The known_hosts copy ssh is pointed at.

Source

pub fn identity(&self) -> Option<&Path>

The identity file passed with -i, when one is configured.

Source

pub fn ssh_argv(&self, remote_command: Option<&RemoteCommand>) -> Vec<OsString>

ssh argv: -T -p <port> [-i <key>] -o k=v… -- user@host [command]. remote_command is sent to the remote shell as one argument; a RemoteCommand can only be built injection-safe.

Source

pub fn sftp_argv(&self) -> Vec<OsString>

sftp argv: -q -b - -P <port> [-i <key>] -o k=v… -- user@host (the batch comes on stdin).

Source

pub async fn sftp_batch( &self, ops: &[SftpOp], ) -> Result<ProcessOutput, CoreError>

Run sftp with ops as the batch on stdin, then close stdin. Every op is rendered first, so one op with an unsafe path refuses the whole batch before anything spawns.

Source

pub fn require_success( &self, operation: &str, out: ProcessOutput, ) -> Result<ProcessOutput, CoreError>

Map a finished invocation to Ok only when it exited 0 within its timeout with nothing on stderr. Anything else is CoreError::TransportFailed whose detail is the scrubbed stderr tail (never the stdout, never the key).

Source

pub async fn exec_powershell( &self, script: &WinScript, ) -> Result<Value, CoreError>

Run a fixed WinScript on a Windows host over ssh and return its result. The remote command is built by winps::encoded_command (the typed RemoteCommand::powershell_encoded, held to the 8000 character budget before anything spawns); success needs exit 0 within the per-call timeout and exactly one IGN-RESULT: stdout line, and anything else, CLIXML on stderr included, is CoreError::TransportFailed (see winps).

Source

pub async fn exec_powershell_within( &self, script: &WinScript, limit: Duration, ) -> Result<Value, CoreError>

exec_powershell with limit as the per-call timeout instead of ssh.op_timeout_s (the commit’s, which must not outlive the scan-lock hold by much, review WR-04).

Source

pub async fn exec_posix( &self, op: &str, command: &RemoteCommand, ) -> Result<Value, CoreError>

Run one POSIX command (built by RemoteCommand::posix) on a Linux host over ssh and return the JSON of its one IGN-RESULT: stdout line. op names the script operation in every error. Success needs exit 0 within the per-call timeout and exactly one sentinel line; a non-zero exit, a timeout, a missing or doubled sentinel and text after the sentinel that is not JSON are all CoreError::TransportFailed naming op. The detail carries a scrubbed stderr tail and never the stdout.

Source

pub async fn exec_posix_within( &self, op: &str, command: &RemoteCommand, limit: Duration, ) -> Result<Value, CoreError>

exec_posix with limit as the per-call timeout instead of ssh.op_timeout_s (the commit’s, review WR-04).

Source

pub async fn exec_posix_status( &self, op: &str, command: &RemoteCommand, ) -> Result<(), CoreError>

Run one POSIX command (built by RemoteCommand::posix) for its exit status alone: success is exit 0 within the per-call timeout, and the stdout is not read. For a program that prints nothing on success (mv), where no IGN-RESULT: line can be asked for without wrapping the program in a shell script. A non-zero exit and a timeout are CoreError::TransportFailed naming op, with the scrubbed stderr tail and never the stdout.

Trait Implementations§

Source§

impl Debug for RemoteShell

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more