Skip to content

Commit

Permalink
WIP get users
Browse files Browse the repository at this point in the history
  • Loading branch information
ViViDboarder committed Apr 5, 2019
1 parent d38a2e8 commit cbdd7b8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/bw_admin.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -127,4 +145,10 @@ impl Client {

self.post("/invite", &json)
}

/// Get all existing users
pub fn users(&mut self) -> Result<Vec<User>, Box<Error>> {
let all_users: Vec<User> = self.get("/users").json()?;
Ok(all_users)
}
}
12 changes: 12 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit cbdd7b8

Please sign in to comment.