Skip to main content

ConfigService

Struct ConfigService 

Source
pub struct ConfigService<'a> { /* private fields */ }
Expand description

SSH config file operations.

Implementations§

Source§

impl<'a> ConfigService<'a>

Source

pub fn new(paths: &'a SshPaths) -> Self

Source

pub async fn load(&self) -> Result<ConfigAst>

Load and parse the SSH config into a lossless AST (cached); returns an empty AST when the file is missing.

§Errors

Error::Io when the file is unreadable.

Source

pub async fn save(&self, ast: &ConfigAst) -> Result<()>

Save the AST atomically with 0o600 permissions.

§Errors

Error::ConfigWriteFailed (write/rename) or Error::Io (chmod).

Source

pub async fn resolve_host(&self, host: &str) -> Result<ResolvedHost>

Resolve a host alias to a ResolvedHost, expanding Includes and tokens.

§Errors

Error::ConfigIncludeCycle or Error::Io.

Source

pub async fn parse_typed(&self) -> Result<SshConfig>

Parse the config into an ssh2_config_rs::SshConfig (supports .query(host)).

§Errors

Error::ConfigParseFailed or Error::Io.

Source

pub fn get_host_directive( ast: &ConfigAst, host: &str, key: &str, ) -> Option<String>

Get a directive value for a host from the AST; first match wins.

Source

pub fn get_all_host_directives( ast: &ConfigAst, host: &str, ) -> Vec<(String, String)>

Get all directives for a host.

Source

pub fn add_host( ast: &mut ConfigAst, name: &str, directives: Vec<(String, String)>, ) -> Result<()>

Add a new Host block.

§Errors

Error::DuplicateHost if one with the given name already exists.

Source

pub fn remove_host(ast: &mut ConfigAst, name: &str) -> Result<()>

Remove a Host block by name.

§Errors

Error::HostNotFound if absent.

Source

pub fn rename_host( ast: &mut ConfigAst, old_name: &str, new_name: &str, ) -> Result<()>

Rename a Host block.

§Errors

Error::HostNotFound if old_name is absent, or Error::DuplicateHost if new_name exists.

Source

pub fn upsert_managed_block( ast: &mut ConfigAst, name: &str, directives: Vec<(String, String)>, )

Add a managed block (or replace an existing one).

Source

pub fn remove_managed_block(ast: &mut ConfigAst, name: &str) -> Result<()>

Remove a managed block by name.

§Errors

Error::ManagedBlockNotFound if absent.

Source

pub fn list_managed_blocks(ast: &ConfigAst) -> Vec<String>

List all managed block names.

Source

pub async fn ensure_config_file(&self) -> Result<()>

Create ~/.ssh (0o700) and the config file (0o600) if missing.

§Errors

Error::Io on failure.

Source

pub fn config_path(&self) -> &Path

Get the path to the config file.

Source

pub async fn edit<F>(&self, f: F) -> Result<()>
where F: FnOnce(&mut ConfigAst) -> Result<()>,

Load, mutate via f, then save.

§Errors

From any step: ensure, load, f, or save.

Source

pub async fn diagnose(&self) -> Result<Vec<Diagnostic>>

Diagnose the config: proxy conflicts, duplicate aliases, Host * placement, and missing or .pub IdentityFiles.

§Errors

Error::Io.

Auto Trait Implementations§

§

impl<'a> Freeze for ConfigService<'a>

§

impl<'a> RefUnwindSafe for ConfigService<'a>

§

impl<'a> Send for ConfigService<'a>

§

impl<'a> Sync for ConfigService<'a>

§

impl<'a> Unpin for ConfigService<'a>

§

impl<'a> UnsafeUnpin for ConfigService<'a>

§

impl<'a> UnwindSafe for ConfigService<'a>

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