WIP get users

This commit is contained in:
ViViDboarder 2019-04-05 11:49:32 -07:00
parent d38a2e8b37
commit cbdd7b8c5b
2 changed files with 37 additions and 1 deletions

View File

@ -1,12 +1,30 @@
extern crate reqwest; extern crate reqwest;
extern crate serde_json; extern crate serde;
use reqwest::Response; use reqwest::Response;
use serde::Deserialize;
use std::collections::HashMap; use std::collections::HashMap;
use std::error::Error;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
const COOKIE_LIFESPAN: Duration = Duration::from_secs(20 * 60); 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 { pub struct Client {
url: String, url: String,
admin_token: String, admin_token: String,
@ -127,4 +145,10 @@ impl Client {
self.post("/invite", &json) 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)
}
} }

View File

@ -16,6 +16,18 @@ fn main() {
config.get_bitwarden_admin_token().clone(), 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 // TODO: Use command line args to differentiate if we invite once or start loop
if let Err(e) = invite_from_ldap(&config, &mut client) { if let Err(e) = invite_from_ldap(&config, &mut client) {
println!("{}", e); println!("{}", e);