Skip to content

Commit

Permalink
feat: add email source (#3141)
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath authored Nov 24, 2024
1 parent 4e0979c commit fbd4d1d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 34 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tailcall-tracker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ whoami = "1.5.2"
strum = "0.26.3"
convert_case = { workspace = true }
http = { workspace = true }
regex = "1.11.1"
69 changes: 35 additions & 34 deletions tailcall-tracker/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,50 +118,39 @@ async fn email() -> HashSet<String> {
}

// From Git
async fn git() -> Option<String> {
let output = Command::new("git")
async fn git() -> Result<Output> {
Ok(Command::new("git")
.args(["config", "--global", "user.email"])
.output()
.await
.ok()?;

parse(output)
.await?)
}

// From SSH Keys
async fn ssh() -> Option<HashSet<String>> {
// Single command to find all unique email addresses from .pub files
let output = Command::new("sh")
.args([
"-c",
"cat ~/.ssh/*.pub | grep -o '[^ ]\\+@[^ ]\\+\\.[^ ]\\+'",
])
async fn ssh() -> Result<Output> {
Ok(Command::new("sh")
.args(["-c", "cat ~/.ssh/*.pub"])
.output()
.await
.ok()?;

Some(parse(output)?.lines().map(|o| o.to_owned()).collect())
.await?)
}

let git_email = git().await;
let ssh_emails = ssh().await;
let mut email_ids = HashSet::new();

if let Some(email) = git_email {
if !email.trim().is_empty() {
email_ids.insert(email.trim().to_string());
}
}

if let Some(emails) = ssh_emails {
for email in emails {
if !email.trim().is_empty() {
email_ids.insert(email.trim().to_string());
}
}
// From defaults read MobileMeAccounts Accounts
async fn mobile_me() -> Result<Output> {
Ok(Command::new("defaults")
.args(["read", "MobileMeAccounts", "Accounts"])
.output()
.await?)
}

email_ids
vec![git().await, ssh().await, mobile_me().await]
.into_iter()
.flat_map(|output| {
output
.ok()
.and_then(parse)
.map(parse_email)
.unwrap_or_default()
})
.collect::<HashSet<String>>()
}

// Generates a random client ID
Expand Down Expand Up @@ -215,6 +204,18 @@ fn os_name() -> String {
System::long_os_version().unwrap_or("Unknown".to_string())
}

// Should take arbitrary text and be able to extract email addresses
fn parse_email(text: String) -> Vec<String> {
let mut email_ids = Vec::new();

let re = regex::Regex::new(r"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}").unwrap();
for email in re.find_iter(&text) {
email_ids.push(email.as_str().to_string());
}

email_ids
}

#[cfg(test)]
mod tests {

Expand Down
3 changes: 3 additions & 0 deletions tailcall-tracker/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ pub enum Error {

#[debug(fmt = "Tokio Join Error: {}", _0)]
TokioJoin(tokio::task::JoinError),

#[debug(fmt = "IO Error: {}", _0)]
IO(std::io::Error),
}

pub type Result<A> = std::result::Result<A, Error>;

1 comment on commit fbd4d1d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running 30s test @ http://localhost:8000/graphql

4 threads and 100 connections

Thread Stats Avg Stdev Max +/- Stdev
Latency 4.02ms 1.88ms 27.69ms 79.05%
Req/Sec 6.38k 836.46 8.32k 94.42%

761786 requests in 30.03s, 3.82GB read

Requests/sec: 25366.44

Transfer/sec: 130.20MB

Please sign in to comment.