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
impl SSHConfig
pub fn builder() -> SSHConfigBuilder
pub fn config_file(&self) -> Option<&str>
Source§impl SSHConfig
impl SSHConfig
Sourcepub fn validate(&self) -> Result<(), SshConfigError>
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:
- Verifying that the file exists and is accessible
- Opening the file for reading
- 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_existsfor details) SshConfigError::OpenFailed- The file exists but cannot be openedSshConfigError::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),
}Sourcepub fn parse(&self) -> Result<Option<SshConfig>, SshConfigError>
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 (theconfig_filefield isNone).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);
}
}