Skip to content

Commit f30ad07

Browse files
authored
Merge pull request #47 from Deedasmi/master
Initial lib documentation.
2 parents be73ba8 + 966648a commit f30ad07

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

inquisitor_lib/src/lib.rs

+22-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! This library is intended for use in both the Inquisitor Agent and the Inquisitor Receptor.
2+
//! Plugin authors must implement the plugin trait for their desired platform, but they
3+
//! may also make use of several convience functions included in this library.
14
#[macro_use]
25
extern crate serde_derive;
36
extern crate serde;
@@ -19,7 +22,8 @@ use std::collections::HashMap;
1922
use std::path::PathBuf;
2023
use std::time::{SystemTime, UNIX_EPOCH};
2124

22-
25+
/// This struct is for communication between agent and receptor.
26+
/// Plugins should not use this directly
2327
#[derive(Serialize, Deserialize, Debug)]
2428
pub struct Status {
2529
pub sender: String,
@@ -28,13 +32,18 @@ pub struct Status {
2832
pub plugin_name: String
2933
}
3034

35+
/// A utility function that returns the current timestamp in seconds
3136
pub fn current_ts() -> i64 {
3237
SystemTime::now()
3338
.duration_since(UNIX_EPOCH)
3439
.expect("Error getting system time !?")
3540
.as_secs() as i64
3641
}
3742

43+
/// A utility function that returns a deserialized object from a configuration file.
44+
/// Plugins should use this instead of manipulating their own configuration file
45+
///
46+
/// # TODO examples
3847
pub fn read_cfg<ConfigT>(cfg_file_path: &PathBuf) -> Result<ConfigT, String>
3948
where
4049
ConfigT: DeserializeOwned
@@ -45,11 +54,15 @@ where
4554
Ok(cfg)
4655
}
4756

57+
/// This trait is required by agent plugins
4858
pub trait AgentPlugin {
59+
/// Returns the plugin's name. Sent to the server to tag plugin messages
4960
fn name(&self) -> &'static str;
50-
61+
/// This is the 'worker' function, and will be called when the ready fucntion returns true.
62+
/// Currently this requires plugins to return a string.
63+
/// An `Ok` will be sent to the server, while currently an `Err` is output to the terminal on the agent
5164
fn gather(&mut self) -> Result<String, String>;
52-
65+
/// This function tells the agent if the plugin is ready to be run.
5366
fn ready(&self) -> bool;
5467
}
5568

@@ -61,10 +74,14 @@ pub fn get_url_params(req: &Request) -> HashMap<String, String> {
6174
hash_query
6275
}
6376

77+
/// This trait is required by receptor plugins
6478
pub trait ReceptorPlugin {
79+
/// Returns the plugin's name. Stored in the database with the message returnd
6580
fn name(&self) -> &'static str;
66-
81+
/// This is the 'worker' function, and will be called when the ready fucntion returns true.
82+
/// Currently this requires plugins to return a string.
83+
/// An `Ok` will be stored, while currently an `Err` is output to the terminal on the receptor
6784
fn gather(&mut self, db_conn: &Connection) -> Result<String, String>;
68-
85+
/// This function tells the receptor if the plugin is ready to be run.
6986
fn ready(&self) -> bool;
7087
}

0 commit comments

Comments
 (0)