refactor(settings): rename `BounceLimit(s)` to `DeliveryProblemLimit(s)`

This commit is contained in:
Vijay Budhram 2018-11-27 09:10:06 -05:00
Родитель abf4456098
Коммит 1d5e817cc1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: D49B640E659DCB9E
6 изменённых файлов: 39 добавлений и 30 удалений

Просмотреть файл

@ -5,7 +5,7 @@
"aws": {
"region": "us-west-2"
},
"bouncelimits": {
"deliveryproblemlimits": {
"enabled": true,
"complaint": [
{ "period": "day", "limit": 0 },

Просмотреть файл

@ -79,11 +79,11 @@ fn successful_version() {
assert_eq!(
body,
json!({
"build": "TBD",
"commit": "TBD",
"source": "https://github.com/mozilla/fxa-email-service",
"version": "TBD"
})
"build": "TBD",
"commit": "TBD",
"source": "https://github.com/mozilla/fxa-email-service",
"version": "TBD"
})
.to_string()
);
assert_eq!(response.status(), Status::Ok);

Просмотреть файл

@ -20,7 +20,7 @@ use super::{
core::{Client as DbClient, DataType},
};
use queues::notification::{BounceSubtype, BounceType, ComplaintFeedbackType};
use settings::{BounceLimit, BounceLimits, Settings};
use settings::{DeliveryProblemLimit, DeliveryProblemLimits, Settings};
use types::{
email_address::EmailAddress,
error::{AppErrorKind, AppResult},
@ -38,7 +38,7 @@ use types::{
pub struct DeliveryProblems<D: AuthDb> {
auth_db: D,
db: DbClient,
limits: BounceLimits,
limits: DeliveryProblemLimits,
}
impl<D> DeliveryProblems<D>
@ -50,7 +50,7 @@ where
DeliveryProblems {
auth_db,
db: DbClient::new(settings),
limits: settings.bouncelimits.clone(),
limits: settings.deliveryproblemlimits.clone(),
}
}
@ -60,9 +60,9 @@ where
///
/// If matching records are found,
/// they are checked against thresholds
/// defined in the [`BounceLimits` setting][limits].
/// defined in the [`DeliveryProblemLimits` setting][limits].
///
/// [limits]: ../settings/struct.BounceLimits.html
/// [limits]: ../settings/struct.DeliveryProblemLimits.html
pub fn check(&self, address: &EmailAddress) -> AppResult<()> {
let problems = self.auth_db.get_bounces(address)?;
// TODO: When we start reading from the new datastore, use Utc::now() here instead
@ -171,7 +171,12 @@ where
unsafe impl<D> Sync for DeliveryProblems<D> where D: AuthDb {}
fn is_limit_violation(count: u8, created_at: u64, timestamp: u64, limits: &[BounceLimit]) -> bool {
fn is_limit_violation(
count: u8,
created_at: u64,
timestamp: u64,
limits: &[DeliveryProblemLimit],
) -> bool {
for limit in limits.iter() {
if count > limit.limit && created_at >= timestamp - limit.period.0 {
return true;

Просмотреть файл

@ -47,9 +47,10 @@ fn check_no_bounces() {
}
}
fn create_settings(bounce_limits: Json) -> Settings {
fn create_settings(delivery_problem_limits: Json) -> Settings {
let mut settings = Settings::default();
settings.bouncelimits = serde_json::from_value(bounce_limits).expect("JSON error");
settings.deliveryproblemlimits =
serde_json::from_value(delivery_problem_limits).expect("JSON error");
settings.redis.host = Host(String::from("127.0.0.1"));
settings.redis.port = 6379;
settings

Просмотреть файл

@ -124,7 +124,7 @@ pub struct AwsKeys {
/// A definition object for a bounce/complaint limit.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct BounceLimit {
pub struct DeliveryProblemLimit {
/// The time period
/// within which to limit bounces/complaints.
pub period: Duration,
@ -137,21 +137,21 @@ pub struct BounceLimit {
/// Controls the thresholds and behaviour
/// for bounce and complaint reports.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct BounceLimits {
/// Controls whether to enable bounce limits.
pub struct DeliveryProblemLimits {
/// Controls whether to enable delivery problem limits.
/// If set to `false`,
/// bounce and complaint records in the database
/// are ignored.
pub enabled: bool,
/// Limits for complaints/spam reports.
pub complaint: Vec<BounceLimit>,
pub complaint: Vec<DeliveryProblemLimit>,
/// Limits for hard (permanent) bounces.
pub hard: Vec<BounceLimit>,
pub hard: Vec<DeliveryProblemLimit>,
/// Limits for soft (transient) bounces.
pub soft: Vec<BounceLimit>,
pub soft: Vec<DeliveryProblemLimit>,
}
/// Settings for logging.
@ -303,10 +303,10 @@ pub struct Settings {
/// Controls the thresholds and behaviour
/// for bounce and complaint reports.
/// If bounce limits are enabled,
/// If delivery problem limits are enabled,
/// emails sent to offending addresses
/// will fail with a `429` error.
pub bouncelimits: BounceLimits,
pub deliveryproblemlimits: DeliveryProblemLimits,
/// The env sets which environment we are in.
/// It defaults to `dev` if not set.

Просмотреть файл

@ -64,7 +64,7 @@ fn env_vars_take_precedence() {
"FXA_EMAIL_AWS_SQSURLS_COMPLAINT",
"FXA_EMAIL_AWS_SQSURLS_DELIVERY",
"FXA_EMAIL_AWS_SQSURLS_NOTIFICATION",
"FXA_EMAIL_BOUNCELIMITS_ENABLED",
"FXA_EMAIL_DELIVERYPROBLEMLIMITS_ENABLED",
"FXA_EMAIL_ENV",
"FXA_EMAIL_LOG_LEVEL",
"FXA_EMAIL_LOG_FORMAT",
@ -127,7 +127,7 @@ fn env_vars_take_precedence() {
)),
}
};
let bounce_limits_enabled = !settings.bouncelimits.enabled;
let delivery_problem_limits_enabled = !settings.deliveryproblemlimits.enabled;
let current_env = if settings.env == Env::Dev {
Env::Prod
} else {
@ -210,8 +210,8 @@ fn env_vars_take_precedence() {
&aws_sqs_urls.notification.0,
);
env::set_var(
"FXA_EMAIL_BOUNCELIMITS_ENABLED",
&bounce_limits_enabled.to_string(),
"FXA_EMAIL_DELIVERYPROBLEMLIMITS_ENABLED",
&delivery_problem_limits_enabled.to_string(),
);
env::set_var("FXA_EMAIL_HMACKEY", &hmac_key.to_string());
env::set_var("FXA_EMAIL_ENV", current_env.as_ref());
@ -246,7 +246,10 @@ fn env_vars_take_precedence() {
Ok(env_settings) => {
assert_eq!(env_settings.authdb.baseuri, BaseUri(auth_db_base_uri));
assert_eq!(env_settings.aws.region, AwsRegion(aws_region.to_string()));
assert_eq!(env_settings.bouncelimits.enabled, bounce_limits_enabled);
assert_eq!(
env_settings.deliveryproblemlimits.enabled,
delivery_problem_limits_enabled
);
assert_eq!(env_settings.env, current_env);
assert_eq!(env_settings.hmackey, hmac_key);
assert_eq!(env_settings.log.level, log.level);
@ -475,9 +478,9 @@ fn invalid_aws_notification_queue_url() {
}
#[test]
fn invalid_bouncelimits_enabled() {
let _clean_env = CleanEnvironment::new(vec!["FXA_EMAIL_BOUNCELIMITS_ENABLED"]);
env::set_var("FXA_EMAIL_BOUNCELIMITS_ENABLED", "falsey");
fn invalid_deliveryproblemslimits_enabled() {
let _clean_env = CleanEnvironment::new(vec!["FXA_EMAIL_DELIVERYPROBLEMLIMITS_ENABLED"]);
env::set_var("FXA_EMAIL_DELIVERYPROBLEMLIMITS_ENABLED", "falsey");
match Settings::new() {
Ok(_settings) => assert!(false, "Settings::new should have failed"),