DeviceSession

Struct DeviceSession 

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

Manages an active SSH session to an Aurora device

This struct encapsulates the device connection and provides convenient methods for executing commands, both as regular user and as root via devel-su.

§Example

use audb::tools::session::DeviceSession;
use audb::tools::types::Device;

let mut session = DeviceSession::connect(&device).await?;
let output = session.exec("uname -a").await?;
println!("System info: {:?}", output);

Implementations§

Source§

impl DeviceSession

Source

pub fn connect(device: &Device) -> Result<Self, DeviceError>

Connect to a device and return an active session

§Arguments
  • device - The device configuration to connect to
§Returns

A new DeviceSession or an error if connection fails

§Errors

Returns DeviceError::ConnectionFailed if the SSH connection cannot be established

Source

pub fn exec(&mut self, command: &str) -> Result<Vec<String>>

Execute command as regular user

§Arguments
  • command - The shell command to execute
§Returns

A vector of output lines (stdout) from the command

§Errors

Returns an error if command execution fails or returns non-zero exit code

Source

pub fn exec_as_root( &mut self, command: &str, ) -> Result<Vec<String>, DeviceError>

Execute command as root via devel-su

This method uses the device’s configured root password to execute commands with root privileges using Aurora OS’s devel-su mechanism.

§Arguments
  • command - The shell command to execute as root
§Returns

A vector of output lines (stdout) from the command

§Errors
  • Returns DeviceError::RootPasswordNotConfigured if no root password is set
  • Returns an error if command execution fails
§Security

The password and command are properly escaped to prevent shell injection.

Source

pub fn upload_file( &mut self, local_path: &Path, remote_path: &Path, ) -> Result<()>

Upload file to device via SFTP

§Arguments
  • local_path - Path to the local file to upload
  • remote_path - Destination path on the remote device
§Errors

Returns an error if file upload fails

Source

pub fn read_file_base64( &mut self, remote_path: &Path, ) -> Result<String, DeviceError>

Read remote file contents as base64 string

This method is useful for reading files that may be owned by root, as it uses the root password if configured.

§Arguments
  • remote_path - Path to the file on the remote device
§Returns

Base64-encoded contents of the file

§Errors
  • Returns DeviceError::RootPasswordNotConfigured if no root password is set
  • Returns an error if file reading fails
Source

pub fn device(&self) -> &Device

Get a reference to the underlying device configuration

Source

pub fn device_name(&self) -> String

Get the device’s display name

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, 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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V