diff --git a/crates/api-grub/src/monitoring.rs b/crates/api-grub/src/monitoring.rs index 461b32c..aeacf2d 100644 --- a/crates/api-grub/src/monitoring.rs +++ b/crates/api-grub/src/monitoring.rs @@ -76,7 +76,7 @@ pub async fn get_metrics_from_monitoring(duration: usize, delay: usize) -> anyho /// assert_eq!(a.get_measure_info(vec.clone()).await, Ok(())); /// ``` /// -#[derive(Debug, Clone)] +#[derive(Clone)] pub struct MonitoringImporter { ip : String, login : String, @@ -86,6 +86,17 @@ pub struct MonitoringImporter { } impl MonitoringImporter { + /// The most simple constructor for `MonitoringImporter` + /// + /// Returns `Self` object that is constructing according to + /// env vars: + /// - `ENODE_MONITORING_IP` + /// - `ENODE_MONITORING_LOGIN` + /// - `ENODE_MONITORING_PASSWORD` + /// + /// If env vars will not be set, it returns `Self` with + /// empty fields + /// pub async fn new() -> Self { MonitoringImporter { ip : env::var("ENODE_MONITORING_IP").unwrap_or_else(|_| String::new()), @@ -95,12 +106,29 @@ impl MonitoringImporter { ts : String::new(), } } + /// Function that checks is current `MonitoringImporter` valid + /// and can be used to pull and push info to and from CM + /// async fn is_valid(&self) -> bool { !self.ip.is_empty() && !self.login.is_empty() && !self.password.is_empty() } + /// A setter of `timestamp` + /// + /// This function is needed to set a `timestamp` after + /// CM session creation. + /// + /// This `timestamp` is a date of creation a session + /// on the CM Server async fn set_ts(&mut self, ts: &str) { self.ts = ts.to_owned(); } + /// A function for creation CM session + /// + /// Returns OK(()) if session was created and there were + /// no errors (neither internal no external) + /// + /// *Also* it saves ts and access-key in it's runtime environment, + /// there's no way to get access-key of session pub async fn start_session(&mut self) -> anyhow::Result<()> { if !self.is_valid().await { return Err(Error::msg("Invalid eNODE-Monitoring configuration")); @@ -277,4 +305,16 @@ impl MonitoringImporter { value : val.clone() }) } +} + +impl std::fmt::Debug for MonitoringImporter { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("MonitoringImporter") + .field("ip", &self.ip) + .field("login", &self.login) + .field("password", &"****") + .field("access_key", &"HIDDEN") + .field("ts", &self.ts) + .finish() + } } \ No newline at end of file