Skip to content

Commit

Permalink
feat: Set default timeout to 10s (#1251)
Browse files Browse the repository at this point in the history
* Add timeout

* Set default timeout to 10s

* Use duration in u64 (seconds)

* Add user/pass to openapi

* default hello_name to example.org

* Fix lint
  • Loading branch information
amaury1093 authored Jan 8, 2023
1 parent 9bf437b commit d04f84c
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 118 deletions.
72 changes: 72 additions & 0 deletions Cargo.lock

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

28 changes: 14 additions & 14 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ Then send a `POST http://localhost:8080/v0/check_email` request with the followi

These are the environment variables used to configure the HTTP server. To pass them to the Docker container, use the `-e {ENV_VAR}={VALUE}` flag.

| Env Var | Required? | Description | Default |
| ----------------------------------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------ |
| `RCH_ENABLE_BULK` | No | If set to `1`, then bulk verification endpoints will be added to the backend. | 0 |
| `DATABASE_URL` | Yes if `RCH_ENABLE_BULK==1` | Database connection string for storing results and task queue | not defined |
| `RCH_HTTP_HOST` | No | The host name to bind the HTTP server to. | `127.0.0.1` |
| `PORT` | No | The port to bind the HTTP server to, often populated by the cloud provider. | `8080` |
| `RCH_HOTMAIL_USE_HEADLESS` | No | Set to a running WebDriver process endpoint (e.g. `http://localhost:4444`) to use a headless navigator to Hotmail's password recovery page to check Hotmail/Outlook addresses. We recommend `chromedriver` as it allows parallel requests. | not defined |
| `RCH_FROM_EMAIL` | No | The email to use in the `MAIL FROM:` SMTP command. | `[email protected]` |
| `RCH_SENTRY_DSN` | No | If set, bug reports will be sent to this [Sentry](https://sentry.io) DSN. | not defined |
| `RCH_HEADER_SECRET` | No | If set, then all HTTP requests must have the `x-reacher-secret` header set to this value. This is used to protect the backend against public unwanted HTTP requests. | undefined |
| `RCH_DATABASE_MAX_CONNECTIONS` | No | (Bulk) Connections created for the database pool | 5 |
| `RCH_MINIMUM_TASK_CONCURRENCY` | No | (Bulk) Minimum number of concurrent running tasks below which more tasks are fetched | 10 |
| `RCH_MAXIMUM_CONCURRENT_TASK_FETCH` | No | (Bulk) Maximum number of tasks fetched at once | 20 |
| `RUST_LOG` | No | One of `trace,debug,warn,error,info`. 💡 PRO TIP: `RUST_LOG=debug` is very handful for debugging purposes. | not defined |
| Env Var | Required? | Description | Default |
| ----------------------------------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------- |
| `RCH_ENABLE_BULK` | No | If set to `1`, then bulk verification endpoints will be added to the backend. | 0 |
| `DATABASE_URL` | Yes if `RCH_ENABLE_BULK==1` | Database connection string for storing results and task queue | not defined |
| `RCH_HTTP_HOST` | No | The host name to bind the HTTP server to. | `127.0.0.1` |
| `PORT` | No | The port to bind the HTTP server to, often populated by the cloud provider. | `8080` |
| `RCH_HOTMAIL_USE_HEADLESS` | No | Set to a running WebDriver process endpoint (e.g. `http://localhost:4444`) to use a headless navigator to Hotmail's password recovery page to check Hotmail/Outlook addresses. We recommend `chromedriver` as it allows parallel requests. | not defined |
| `RCH_SMTP_TIMEOUT` | No | The default timeout of each SMTP connection, in seconds. Can be overwritten in each request using the `smtp_timeout` field. | 10s |
| `RCH_SENTRY_DSN` | No | If set, bug reports will be sent to this [Sentry](https://sentry.io) DSN. | not defined |
| `RCH_HEADER_SECRET` | No | If set, then all HTTP requests must have the `x-reacher-secret` header set to this value. This is used to protect the backend against public unwanted HTTP requests. | undefined |
| `RCH_DATABASE_MAX_CONNECTIONS` | No | (Bulk) Connections created for the database pool | 5 |
| `RCH_MINIMUM_TASK_CONCURRENCY` | No | (Bulk) Minimum number of concurrent running tasks below which more tasks are fetched | 10 |
| `RCH_MAXIMUM_CONCURRENT_TASK_FETCH` | No | (Bulk) Maximum number of tasks fetched at once | 20 |
| `RUST_LOG` | No | One of `trace,debug,warn,error,info`. 💡 PRO TIP: `RUST_LOG=debug` is very handful for debugging purposes. | not defined |

## REST API Documentation

Expand Down
105 changes: 66 additions & 39 deletions backend/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"openapi": "3.0.0",
"info": {
"title": "Reacher",
"version": "0.3.*",
"version": "0.4.*",
"description": "### What is Reacher?\n\nReacher is a powerful, free and open-source email verification API service. It is provided both as a SaaS and as a self-host solution.",
"license": {
"name": "AGPL-3.0 OR Commercial",
"url": "https://github.com/reacherhq/backend/blob/master/LICENSE.md"
"url": "https://github.com/reacherhq/check-if-email-exists/blob/master/LICENSE.md"
},
"contact": {
"name": "Reacher",
Expand Down Expand Up @@ -40,8 +40,7 @@
"is_reachable": "invalid",
"misc": {
"is_disposable": false,
"is_role_account": true,
"gravatar_url": null
"is_role_account": true
},
"mx": {
"accepts_mail": true,
Expand Down Expand Up @@ -110,8 +109,7 @@
"is_reachable": "invalid",
"misc": {
"is_disposable": false,
"is_role_account": true,
"gravatar_url": null
"is_role_account": true
},
"mx": {
"accepts_mail": true,
Expand Down Expand Up @@ -207,10 +205,7 @@
"description": "A human-readable description of the error."
}
},
"required": [
"type",
"message"
]
"required": ["type", "message"]
},
"MiscDetails": {
"title": "MiscDetails",
Expand All @@ -227,13 +222,10 @@
},
"gravatar_url": {
"type": "string",
"description": "The Gravatar url of the image belonging to the given email."
"description": "URL to the email's Gravatar profile picture. It is only populated if check_gravatar is set to true in the request, and if the email has an associated Gravatar."
}
},
"required": [
"is_disposable",
"is_role_account"
]
"required": ["is_disposable", "is_role_account"]
},
"MxDetails": {
"title": "MxDetails",
Expand All @@ -251,10 +243,7 @@
}
}
},
"required": [
"accepts_mail",
"records"
],
"required": ["accepts_mail", "records"],
"description": "Object holding the MX details of the mail server."
},
"SmtpDetails": {
Expand Down Expand Up @@ -309,27 +298,18 @@
"description": "The username of the email, i.e. the part before the \"@\" symbol."
}
},
"required": [
"domain",
"is_valid_syntax",
"username"
]
"required": ["domain", "is_valid_syntax", "username"]
},
"Reachable": {
"type": "string",
"title": "Reachable",
"enum": [
"invalid",
"unknown",
"safe",
"risky"
],
"enum": ["invalid", "unknown", "safe", "risky"],
"description": "An enum to describe how confident we are that the recipient address is real: `safe`, `risky`, `invalid` and `unknown`. Check our FAQ to know the meanings of the 4 possibilities: https://help.reacher.email/email-attributes-inside-json."
},
"CheckEmailInput": {
"title": "CheckEmailInput",
"type": "object",
"description": "Input containing all parameters necessary for an email verification.",
"description": "Input containing all parameters necessary for an email verification, as well as some config on how to perform the verification.",
"properties": {
"from_email": {
"type": "string",
Expand All @@ -345,11 +325,53 @@
},
"proxy": {
"$ref": "#/components/schemas/CheckEmailInputProxy"
},
"smtp_port": {
"type": "number",
"description": "SMTP port to use for email validation. Generally, ports 25, 465, 587 and 2525 are used."
},
"smtp_timeout": {
"type": "number",
"description": "Add optional timeout for the SMTP verification step, in seconds."
},
"yahoo_use_api": {
"type": "boolean",
"description": "For Yahoo email addresses, use Yahoo's API instead of connecting directly to their SMTP servers."
},
"gmail_use_api": {
"type": "boolean",
"description": "For Gmail email addresses, use Gmail's API instead of connecting directly to their SMTP servers."
},
"microsoft365_use_api": {
"type": "boolean",
"description": "For Microsoft 365 email addresses, use OneDrive's API instead of connecting directly to their SMTP servers."
},
"check_gravatar": {
"type": "boolean",
"description": "Whether to check if a gravatar image is existing for the given email."
},
"hotmail_use_headless": {
"type": "string",
"description": "For Hotmail/Outlook email addresses, use a headless navigator connecting to the password recovery page instead of the SMTP server. This assumes you have a WebDriver compatible process running, then pass its endpoint, usually http://localhost:4444. We recommend running chromedriver (and not geckodriver) as it allows parallel requests."
},
"retries": {
"type": "number",
"default": 2,
"description": "Number of retries of SMTP connections to do."
},
"smtp_security": {
"type": "string",
"example": "Opportunistic",
"enum": [
"None",
"Opportunistic",
"Required",
"Wrapper"
],
"description": "How to apply TLS to a SMTP client connection."
}
},
"required": [
"to_email"
]
"required": ["to_email"]
},
"CheckEmailInputProxy": {
"title": "CheckEmailInputProxy",
Expand All @@ -370,12 +392,17 @@
"port": {
"type": "integer",
"description": "The proxy port."
},
"username": {
"type": "string",
"description": "Username to pass to proxy authentication."
},
"password": {
"type": "string",
"description": "Password to pass to proxy authentication."
}
},
"required": [
"host",
"port"
]
"required": ["host", "port"]
}
},
"securitySchemes": {
Expand All @@ -387,4 +414,4 @@
}
}
}
}
}
10 changes: 1 addition & 9 deletions backend/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,15 @@
//! This file contains shared logic for checking one email.
use std::env;
use std::time::Duration;

use check_if_email_exists::{check_email as ciee_check_email, CheckEmailInput, CheckEmailOutput};
use warp::Filter;

use super::sentry_util;

/// Timeout after which we drop the `check-if-email-exists` check. We run the
/// checks twice (to avoid greylisting), so each verification takes 60s max.
const SMTP_TIMEOUT: u64 = 30;

/// Same as `check-if-email-exists`'s check email, but adds some additional
/// inputs and error handling.
pub async fn check_email(mut input: CheckEmailInput) -> CheckEmailOutput {
input.set_smtp_timeout(Duration::from_secs(SMTP_TIMEOUT));
input.set_hotmail_use_headless(env::var("RCH_HOTMAIL_USE_HEADLESS").ok());

pub async fn check_email(input: CheckEmailInput) -> CheckEmailOutput {
let res = ciee_check_email(&input).await;

sentry_util::log_unknown_errors(&res);
Expand Down
Loading

0 comments on commit d04f84c

Please sign in to comment.