diff --git a/src/bw_admin.rs b/src/bw_admin.rs index 86bde4b..7c5de74 100644 --- a/src/bw_admin.rs +++ b/src/bw_admin.rs @@ -1,12 +1,30 @@ extern crate reqwest; -extern crate serde_json; +extern crate serde; use reqwest::Response; +use serde::Deserialize; use std::collections::HashMap; +use std::error::Error; use std::time::{Duration, Instant}; const COOKIE_LIFESPAN: Duration = Duration::from_secs(20 * 60); +#[derive(Deserialize)] +pub struct User { + Email: String, + #[serde(rename = "_Enabled")] + Enabled: bool, +} + +impl User { + pub fn get_email(&self) -> String { + self.Email.clone() + } + pub fn is_enabled(&self) -> bool { + self.Enabled + } +} + pub struct Client { url: String, admin_token: String, @@ -127,4 +145,10 @@ impl Client { self.post("/invite", &json) } + + /// Get all existing users + pub fn users(&mut self) -> Result, Box> { + let all_users: Vec = self.get("/users").json()?; + Ok(all_users) + } } diff --git a/src/main.rs b/src/main.rs index c84b032..a37c8a7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,18 @@ fn main() { config.get_bitwarden_admin_token().clone(), ); + match client.users() { + Ok(users) => { + for user in users { + println!("Existing user: {}", user.get_email()); + } + } + Err(e) => { + println!("Could not get users"); + panic!("{}", e); + } + } + // TODO: Use command line args to differentiate if we invite once or start loop if let Err(e) = invite_from_ldap(&config, &mut client) { println!("{}", e);