diff --git a/src/bw_admin.rs b/src/bw_admin.rs index 1f3995b..fc79708 100644 --- a/src/bw_admin.rs +++ b/src/bw_admin.rs @@ -9,26 +9,23 @@ use std::time::{Duration, Instant}; const COOKIE_LIFESPAN: Duration = Duration::from_secs(20 * 60); -fn true_val() -> bool { - true -} - #[derive(Debug)] #[derive(Deserialize)] pub struct User { #[serde(rename = "Email")] email: String, - #[serde(rename = "_Enabled")] - #[serde(default = "true_val")] - enabled: bool, + #[serde(rename = "_Status")] + status: i32, } impl User { pub fn get_email(&self) -> String { self.email.clone() } - pub fn is_enabled(&self) -> bool { - self.enabled + + pub fn is_disabled(&self) -> bool { + // HACK: Magic number + self.status != 2 } } @@ -158,18 +155,4 @@ impl Client { let all_users: Vec = self.get("/users").json()?; Ok(all_users) } - - /// Get all invited users - pub fn invites(&mut self) -> Result, Box> { - let all_invites: Vec = self.get("/invites").json()?; - Ok(all_invites) - } - - /// Get all users and invites - pub fn users_and_invites(&mut self) -> Result, Box> { - let mut all_users = self.users()?; - let mut invites = self.invites()?; - all_users.append(&mut invites); - Ok(all_users) - } } diff --git a/src/main.rs b/src/main.rs index 560bb37..55d6438 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,14 +41,14 @@ fn invite_users( /// Creates set of email addresses for users that already exist in Bitwarden fn get_existing_users(client: &mut bw_admin::Client) -> Result, Box> { - let all_users = client.users_and_invites()?; + let all_users = client.users()?; let mut user_emails = HashSet::with_capacity(all_users.len()); for user in all_users { user_emails.insert(user.get_email()); - if user.is_enabled() { - println!("Existing user or invite found with email: {}", user.get_email()); - } else { + if user.is_disabled() { println!("Existing disabled user found with email: {}", user.get_email()); + } else { + println!("Existing user or invite found with email: {}", user.get_email()); } }