use chrono::prelude::*;
use cognito_user_reader::UserReaderOptions;
use console::style;
use structopt::StructOpt;
#[derive(StructOpt, PartialEq, Debug)]
#[structopt(
name("๐ Cognito User Reader CLI - CUR"),
author("๐ป Roberto Huertas <roberto.huertas@outlook.com>"),
long_about("๐งฐ Utility to retrieve all users in a specific AWS user pool.\n๐ฆ Humbly written with Rust. ๐งก \n๐ https://github.com/robertohuertasm/cognito-user-reader
โโโโโโโโโโ โโโโโโโโโโ โโโโโโโโโโ โโโ
โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ โโโ
โโโ โโโ โโโโโโโโโโโ โโโ โโโ โโโ
โโโ โโโ โโโโโโโโโโโ โโโ โโโ โโโ
โโโโโโโโโโโโโโโโโโโโ โโโ โโโโโโโโโโโโโโโโโโโ
โโโโโโโ โโโโโโโ โโโ โโโ โโโโโโโโโโโโโโโโโโ ")
)]
#[allow(clippy::struct_excessive_bools, clippy::empty_line_after_outer_attr)]
pub struct Cli {
#[structopt()]
pub pool_id: String,
#[structopt(short = "a", long)]
pub attributes_to_get: Option<Vec<String>>,
#[structopt(short = "i", long)]
pub filtered_user_ids: Option<Vec<String>>,
#[structopt(short = "n", long)]
pub include_user_ids: bool,
#[structopt(short = "e", long)]
pub filtered_user_emails: Option<Vec<String>>,
#[structopt(short = "m", long)]
pub include_user_emails: bool,
#[structopt(short = "x", long)]
pub max_number_users: Option<i64>,
#[structopt(short, long)]
pub print_screen: bool,
#[structopt(short, long)]
pub show_unconfirmed: bool,
#[structopt(short, long, parse(from_str = parse_date))]
pub created_at: Option<DateTime<Utc>>,
}
impl Cli {
pub const fn to_options(&self) -> UserReaderOptions {
UserReaderOptions {
attributes_to_get: &self.attributes_to_get,
limit_of_users: self.max_number_users,
show_unconfirmed_users: self.show_unconfirmed,
filtered_user_ids: &self.filtered_user_ids,
include_user_ids: self.include_user_ids,
filtered_user_emails: &self.filtered_user_emails,
include_user_emails: self.include_user_emails,
created_at: self.created_at,
}
}
}
#[allow(clippy::cast_possible_wrap)]
fn parse_date(src: &str) -> DateTime<Utc> {
let parsed = src
.split('-')
.filter_map(|x| x.parse::<u32>().ok())
.collect::<Vec<_>>();
if parsed.len() != 3 {
let error_msg = "Review the creation date paramater. Use YYYY-MM-DD. eg. 2020-02-23";
println!("{}", style(error_msg).red());
panic!("{}", error_msg);
}
Utc.ymd(parsed[0] as i32, parsed[1], parsed[2])
.and_hms(23, 59, 59)
}