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
impl Bofh
sourcepub fn new(url: String) -> Result<Self, BofhError>
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.
sourcepub fn run_command(
&self,
command: &str,
args: &[&str]
) -> Result<Value, BofhError>
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.
sourcepub fn login(
&mut self,
username: &str,
password: String
) -> Result<BTreeMap<String, CommandGroup>, BofhError>
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.