mirror of
https://github.com/ViViDboarder/bitwarden_rs_ldap.git
synced 2024-11-21 18:56:27 +00:00
WIP get users
This commit is contained in:
parent
d38a2e8b37
commit
cbdd7b8c5b
@ -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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
12
src/main.rs
12
src/main.rs
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user