Skip to main content

SSHConfig

Struct SSHConfig 

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

SSH client settings.

When config_file is set, Settings::from_file validates that the referenced OpenSSH-style config can be opened and parsed.

Implementations§

Source§

impl SSHConfig

Source§

impl SSHConfig

Source

pub fn validate(&self) -> Result<(), SshConfigError>

Validates the SSH configuration file syntax if a path is provided.

This method performs comprehensive validation of an SSH configuration file by:

  1. Verifying that the file exists and is accessible
  2. Opening the file for reading
  3. Parsing the file contents using strict SSH config syntax rules

If no SSH configuration file is specified (the config_file field is None), this method returns Ok(()) without performing any validation.

§Returns

Returns Ok(()) if:

  • No config file is specified (nothing to validate)
  • The config file exists, can be opened, and contains valid SSH configuration syntax

Returns Err(SshConfigError) if:

  • The specified file does not exist or cannot be accessed
  • The file cannot be opened due to permission issues or other I/O errors
  • The file contents cannot be parsed as valid SSH configuration syntax
§Errors

This method returns an error in the following cases:

  • File existence check fails (see ensure_exists for details)
  • SshConfigError::OpenFailed - The file exists but cannot be opened
  • SshConfigError::ParseFailed - The file contains invalid SSH config syntax
§Examples
use genja_core::settings::SSHConfig;

let config = SSHConfig::builder()
    .config_file("/home/user/.ssh/config")
    .build();

match config.validate() {
    Ok(()) => println!("SSH config is valid"),
    Err(e) => eprintln!("Invalid SSH config: {}", e),
}
Source

pub fn parse(&self) -> Result<Option<SshConfig>, SshConfigError>

Parses the SSH configuration file and returns the parsed configuration.

This method reads and parses an SSH configuration file if one is specified in the config_file field. The parsing follows strict SSH config file syntax rules as defined by OpenSSH. If no configuration file is specified, the method returns Ok(None) without performing any parsing.

§Returns

Returns a Result containing:

  • Ok(Some(SshConfig)) - If a config file is specified and successfully parsed, containing the parsed SSH configuration with all host entries and settings.
  • Ok(None) - If no config file is specified (the config_file field is None).
  • Err(SshConfigError) - If an error occurs during parsing.
§Errors

Returns SshConfigError if:

  • The specified SSH config file does not exist at the given path
  • The file cannot be opened due to permission issues or other I/O errors
  • The file contents cannot be parsed as valid SSH configuration syntax
  • The file contains syntax errors or invalid SSH configuration directives
§Examples
use genja_core::settings::SSHConfig;

let config = SSHConfig::builder()
    .config_file("/home/user/.ssh/config")
    .build();

match config.parse() {
    Ok(Some(ssh_config)) => {
        println!("Successfully parsed SSH config");
    }
    Ok(None) => {
        println!("No SSH config file specified");
    }
    Err(e) => {
        eprintln!("Failed to parse SSH config: {}", e);
    }
}

Trait Implementations§

Source§

impl Clone for SSHConfig

Source§

fn clone(&self) -> SSHConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SSHConfig

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for SSHConfig

Source§

fn default() -> SSHConfig

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for SSHConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for SSHConfig

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.