Struct bofh::Bofh

source ·
pub struct Bofh {
    pub url: String,
    pub motd: Option<String>,
    /* private fields */
}
Expand description

The bofh client communicating with the bofhd server.

Fields§

§url: String

The URL to the bofhd server.

§motd: Option<String>

The Message Of The Day provided by the bofhd server after connection.

Implementations§

source§

impl Bofh

source

pub fn new(url: String) -> Result<Self, BofhError>

Creates a new connection to a bofhd server, and tests the connection by requesting the server’s Message of the Day (which is stored in Self::motd).

§Errors

Will return a BofhError if the connection to the bofhd server fails, or it doesn’t respond to the Self::get_motd command.

source

pub fn run_command( &self, command: &str, args: &[&str] ) -> Result<Value, BofhError>

Run a bofh command on the bofhd server.

Note that this function actually runs the bofhd command run_command bofh_command, and can’t be used to run raw bofhd commands. Those are all exposed through separate functions, such as Self::login and Self::get_motd.

§Errors

Returns a BofhError if the command fails for some reason.

If the bofhd session has expired and this function returns a BofhError::SessionExpiredError, the client might want to reauthenticate using Self::login and then retry the command.

source

pub fn login( &mut self, username: &str, password: String ) -> Result<BTreeMap<String, CommandGroup>, BofhError>

Authenticate with the bofhd server and set up a session. Returns the commands available to the authenticated user.

Note that this consumes password to discourage user-facing clients from holding onto the user’s password. If the user needs to reauthenticate (if Self::run_command later returns a BofhError::SessionExpiredError, for example), please prompt the user for the password again.

§Errors

Returns a BofhError if logging in or getting the commands from the server fail for some reason.

§Panics

Will normally never panic, unless the session identifier returned by the bofhd server is in an invalid format.

source

pub fn get_motd(&self) -> Result<String, BofhError>

Get the current Message of the Day from the bofhd server.

§Errors

Returns a BofhError if the command fails for some reason.

§Panics

Will normally never panic, unless the Message of the Day returned by the bofhd server is in an invalid format.

Trait Implementations§

source§

impl Drop for Bofh

source§

fn drop(&mut self)

Logs the user out of the bofhd session.

Auto Trait Implementations§

§

impl RefUnwindSafe for Bofh

§

impl Send for Bofh

§

impl Sync for Bofh

§

impl Unpin for Bofh

§

impl UnwindSafe for Bofh

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

§

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

§

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