diff --git a/autoendpoint/src/error.rs b/autoendpoint/src/error.rs index 1d80a21c4..ce380bd96 100644 --- a/autoendpoint/src/error.rs +++ b/autoendpoint/src/error.rs @@ -1,6 +1,7 @@ //! Error types and transformations -use crate::server::{RouterError, VapidError}; +use crate::headers::vapid::VapidError; +use crate::routers::RouterError; use actix_web::{ dev::{HttpResponseBuilder, ServiceResponse}, error::{PayloadError, ResponseError}, diff --git a/autoendpoint/src/server/extractors/mod.rs b/autoendpoint/src/extractors/mod.rs similarity index 100% rename from autoendpoint/src/server/extractors/mod.rs rename to autoendpoint/src/extractors/mod.rs diff --git a/autoendpoint/src/server/extractors/notification.rs b/autoendpoint/src/extractors/notification.rs similarity index 97% rename from autoendpoint/src/server/extractors/notification.rs rename to autoendpoint/src/extractors/notification.rs index 549cd67bb..d97ddfb20 100644 --- a/autoendpoint/src/server/extractors/notification.rs +++ b/autoendpoint/src/extractors/notification.rs @@ -1,6 +1,6 @@ use crate::error::{ApiError, ApiErrorKind}; -use crate::server::extractors::notification_headers::NotificationHeaders; -use crate::server::extractors::subscription::Subscription; +use crate::extractors::notification_headers::NotificationHeaders; +use crate::extractors::subscription::Subscription; use crate::server::ServerState; use actix_web::dev::{Payload, PayloadStream}; use actix_web::web::Data; diff --git a/autoendpoint/src/server/extractors/notification_headers.rs b/autoendpoint/src/extractors/notification_headers.rs similarity index 99% rename from autoendpoint/src/server/extractors/notification_headers.rs rename to autoendpoint/src/extractors/notification_headers.rs index 764f3967a..425928346 100644 --- a/autoendpoint/src/server/extractors/notification_headers.rs +++ b/autoendpoint/src/extractors/notification_headers.rs @@ -1,6 +1,6 @@ use crate::error::{ApiError, ApiErrorKind, ApiResult}; -use crate::server::headers::crypto_key::CryptoKeyHeader; -use crate::server::headers::util::{get_header, get_owned_header}; +use crate::headers::crypto_key::CryptoKeyHeader; +use crate::headers::util::{get_header, get_owned_header}; use actix_web::HttpRequest; use autopush_common::util::InsertOpt; use lazy_static::lazy_static; diff --git a/autoendpoint/src/server/extractors/routers.rs b/autoendpoint/src/extractors/routers.rs similarity index 93% rename from autoendpoint/src/server/extractors/routers.rs rename to autoendpoint/src/extractors/routers.rs index 6ddd874ae..e92901e87 100644 --- a/autoendpoint/src/server/extractors/routers.rs +++ b/autoendpoint/src/extractors/routers.rs @@ -1,6 +1,6 @@ -use crate::server::routers::fcm::router::FcmRouter; -use crate::server::routers::webpush::WebPushRouter; -use crate::server::routers::Router; +use crate::routers::fcm::router::FcmRouter; +use crate::routers::webpush::WebPushRouter; +use crate::routers::Router; use crate::server::ServerState; use actix_web::dev::{Payload, PayloadStream}; use actix_web::web::Data; diff --git a/autoendpoint/src/server/extractors/subscription.rs b/autoendpoint/src/extractors/subscription.rs similarity index 95% rename from autoendpoint/src/server/extractors/subscription.rs rename to autoendpoint/src/extractors/subscription.rs index eb3dd4712..c660fcbb9 100644 --- a/autoendpoint/src/server/extractors/subscription.rs +++ b/autoendpoint/src/extractors/subscription.rs @@ -1,10 +1,10 @@ use crate::error::{ApiError, ApiErrorKind, ApiResult}; -use crate::server::extractors::routers::RouterType; -use crate::server::extractors::token_info::{ApiVersion, TokenInfo}; -use crate::server::extractors::user::validate_user; -use crate::server::headers::crypto_key::CryptoKeyHeader; -use crate::server::headers::vapid::{VapidHeader, VapidHeaderWithKey, VapidVersionData}; -use crate::server::{ServerState, VapidError}; +use crate::extractors::routers::RouterType; +use crate::extractors::token_info::{ApiVersion, TokenInfo}; +use crate::extractors::user::validate_user; +use crate::headers::crypto_key::CryptoKeyHeader; +use crate::headers::vapid::{VapidError, VapidHeader, VapidHeaderWithKey, VapidVersionData}; +use crate::server::ServerState; use actix_http::{Payload, PayloadStream}; use actix_web::web::Data; use actix_web::{FromRequest, HttpRequest}; diff --git a/autoendpoint/src/server/extractors/token_info.rs b/autoendpoint/src/extractors/token_info.rs similarity index 96% rename from autoendpoint/src/server/extractors/token_info.rs rename to autoendpoint/src/extractors/token_info.rs index 19cadb656..ad5c52ccc 100644 --- a/autoendpoint/src/server/extractors/token_info.rs +++ b/autoendpoint/src/extractors/token_info.rs @@ -1,5 +1,5 @@ use crate::error::{ApiError, ApiErrorKind}; -use crate::server::headers::util::get_owned_header; +use crate::headers::util::get_owned_header; use actix_http::{Payload, PayloadStream}; use actix_web::{FromRequest, HttpRequest}; use futures::future; diff --git a/autoendpoint/src/server/extractors/user.rs b/autoendpoint/src/extractors/user.rs similarity index 98% rename from autoendpoint/src/server/extractors/user.rs rename to autoendpoint/src/extractors/user.rs index 9f85bab22..c35a9af8d 100644 --- a/autoendpoint/src/server/extractors/user.rs +++ b/autoendpoint/src/extractors/user.rs @@ -1,7 +1,7 @@ //! User validations use crate::error::{ApiErrorKind, ApiResult}; -use crate::server::extractors::routers::RouterType; +use crate::extractors::routers::RouterType; use crate::server::ServerState; use autopush_common::db::{DynamoDbUser, DynamoStorage}; use cadence::{Counted, StatsdClient}; diff --git a/autoendpoint/src/server/headers/crypto_key.rs b/autoendpoint/src/headers/crypto_key.rs similarity index 98% rename from autoendpoint/src/server/headers/crypto_key.rs rename to autoendpoint/src/headers/crypto_key.rs index eab0520b6..f6e58ecfc 100644 --- a/autoendpoint/src/server/headers/crypto_key.rs +++ b/autoendpoint/src/headers/crypto_key.rs @@ -1,4 +1,4 @@ -use crate::server::headers::util::split_key_value; +use crate::headers::util::split_key_value; use std::collections::HashMap; /// Parses the Crypto-Key header (and similar headers) described by diff --git a/autoendpoint/src/server/headers/mod.rs b/autoendpoint/src/headers/mod.rs similarity index 100% rename from autoendpoint/src/server/headers/mod.rs rename to autoendpoint/src/headers/mod.rs diff --git a/autoendpoint/src/server/headers/util.rs b/autoendpoint/src/headers/util.rs similarity index 100% rename from autoendpoint/src/server/headers/util.rs rename to autoendpoint/src/headers/util.rs diff --git a/autoendpoint/src/server/headers/vapid.rs b/autoendpoint/src/headers/vapid.rs similarity index 98% rename from autoendpoint/src/server/headers/vapid.rs rename to autoendpoint/src/headers/vapid.rs index 9bdcb74ba..aa538a433 100644 --- a/autoendpoint/src/server/headers/vapid.rs +++ b/autoendpoint/src/headers/vapid.rs @@ -1,4 +1,4 @@ -use crate::server::headers::util::split_key_value; +use crate::headers::util::split_key_value; use std::collections::HashMap; use thiserror::Error; diff --git a/autoendpoint/src/main.rs b/autoendpoint/src/main.rs index 2b9824942..b76a0ee80 100644 --- a/autoendpoint/src/main.rs +++ b/autoendpoint/src/main.rs @@ -4,8 +4,12 @@ extern crate slog_scope; mod error; +mod extractors; +mod headers; mod logging; mod metrics; +mod routers; +mod routes; mod server; mod settings; mod tags; diff --git a/autoendpoint/src/server/routers/fcm/client.rs b/autoendpoint/src/routers/fcm/client.rs similarity index 97% rename from autoendpoint/src/server/routers/fcm/client.rs rename to autoendpoint/src/routers/fcm/client.rs index 569006c7e..44b092115 100644 --- a/autoendpoint/src/server/routers/fcm/client.rs +++ b/autoendpoint/src/routers/fcm/client.rs @@ -1,6 +1,5 @@ -use crate::server::routers::fcm::error::FcmError; -use crate::server::routers::fcm::settings::FcmCredential; -use crate::server::FcmSettings; +use crate::routers::fcm::error::FcmError; +use crate::routers::fcm::settings::{FcmCredential, FcmSettings}; use reqwest::StatusCode; use serde::Deserialize; use std::collections::HashMap; @@ -118,10 +117,9 @@ struct FcmErrorResponse { #[cfg(test)] pub mod tests { - use crate::server::routers::fcm::client::FcmClient; - use crate::server::routers::fcm::error::FcmError; - use crate::server::routers::fcm::settings::FcmCredential; - use crate::server::FcmSettings; + use crate::routers::fcm::client::FcmClient; + use crate::routers::fcm::error::FcmError; + use crate::routers::fcm::settings::{FcmCredential, FcmSettings}; use std::collections::HashMap; use std::io::Write; use std::path::PathBuf; diff --git a/autoendpoint/src/server/routers/fcm/error.rs b/autoendpoint/src/routers/fcm/error.rs similarity index 98% rename from autoendpoint/src/server/routers/fcm/error.rs rename to autoendpoint/src/routers/fcm/error.rs index 2ca726f12..bf944a2af 100644 --- a/autoendpoint/src/server/routers/fcm/error.rs +++ b/autoendpoint/src/routers/fcm/error.rs @@ -1,5 +1,5 @@ use crate::error::ApiErrorKind; -use crate::server::RouterError; +use crate::routers::RouterError; use actix_web::http::StatusCode; /// Errors that may occur in the Firebase Cloud Messaging router diff --git a/autoendpoint/src/server/routers/fcm/mod.rs b/autoendpoint/src/routers/fcm/mod.rs similarity index 100% rename from autoendpoint/src/server/routers/fcm/mod.rs rename to autoendpoint/src/routers/fcm/mod.rs diff --git a/autoendpoint/src/server/routers/fcm/router.rs b/autoendpoint/src/routers/fcm/router.rs similarity index 93% rename from autoendpoint/src/server/routers/fcm/router.rs rename to autoendpoint/src/routers/fcm/router.rs index 4280ea7af..ea264c511 100644 --- a/autoendpoint/src/server/routers/fcm/router.rs +++ b/autoendpoint/src/routers/fcm/router.rs @@ -1,10 +1,9 @@ use crate::error::{ApiError, ApiResult}; -use crate::server::extractors::notification::Notification; -use crate::server::routers::fcm::client::FcmClient; -use crate::server::routers::fcm::error::FcmError; -use crate::server::routers::fcm::settings::FcmCredential; -use crate::server::routers::{Router, RouterResponse}; -use crate::server::FcmSettings; +use crate::extractors::notification::Notification; +use crate::routers::fcm::client::FcmClient; +use crate::routers::fcm::error::FcmError; +use crate::routers::fcm::settings::{FcmCredential, FcmSettings}; +use crate::routers::{Router, RouterResponse}; use async_trait::async_trait; use autopush_common::util::InsertOpt; use cadence::{Counted, StatsdClient}; @@ -207,18 +206,18 @@ impl Router for FcmRouter { #[cfg(test)] mod tests { use crate::error::ApiErrorKind; - use crate::server::extractors::notification::Notification; - use crate::server::extractors::notification_headers::NotificationHeaders; - use crate::server::extractors::routers::RouterType; - use crate::server::extractors::subscription::Subscription; - use crate::server::routers::fcm::client::tests::{ + use crate::extractors::notification::Notification; + use crate::extractors::notification_headers::NotificationHeaders; + use crate::extractors::routers::RouterType; + use crate::extractors::subscription::Subscription; + use crate::routers::fcm::client::tests::{ make_service_file, mock_fcm_endpoint_builder, mock_token_endpoint, PROJECT_ID, }; - use crate::server::routers::fcm::error::FcmError; - use crate::server::routers::fcm::router::FcmRouter; - use crate::server::routers::RouterError; - use crate::server::routers::{Router, RouterResponse}; - use crate::server::FcmSettings; + use crate::routers::fcm::error::FcmError; + use crate::routers::fcm::router::FcmRouter; + use crate::routers::fcm::settings::FcmSettings; + use crate::routers::RouterError; + use crate::routers::{Router, RouterResponse}; use autopush_common::db::DynamoDbUser; use cadence::StatsdClient; use std::collections::HashMap; diff --git a/autoendpoint/src/server/routers/fcm/settings.rs b/autoendpoint/src/routers/fcm/settings.rs similarity index 100% rename from autoendpoint/src/server/routers/fcm/settings.rs rename to autoendpoint/src/routers/fcm/settings.rs diff --git a/autoendpoint/src/server/routers/mod.rs b/autoendpoint/src/routers/mod.rs similarity index 95% rename from autoendpoint/src/server/routers/mod.rs rename to autoendpoint/src/routers/mod.rs index 34fca1843..2c1ccd8ef 100644 --- a/autoendpoint/src/server/routers/mod.rs +++ b/autoendpoint/src/routers/mod.rs @@ -1,8 +1,8 @@ //! Routers route notifications to user agents use crate::error::ApiResult; -use crate::server::extractors::notification::Notification; -use crate::server::routers::fcm::error::FcmError; +use crate::extractors::notification::Notification; +use crate::routers::fcm::error::FcmError; use actix_web::http::StatusCode; use actix_web::HttpResponse; use async_trait::async_trait; diff --git a/autoendpoint/src/server/routers/webpush.rs b/autoendpoint/src/routers/webpush.rs similarity index 98% rename from autoendpoint/src/server/routers/webpush.rs rename to autoendpoint/src/routers/webpush.rs index ff691ea36..4301061d8 100644 --- a/autoendpoint/src/server/routers/webpush.rs +++ b/autoendpoint/src/routers/webpush.rs @@ -1,7 +1,6 @@ use crate::error::{ApiErrorKind, ApiResult}; -use crate::server::extractors::notification::Notification; -use crate::server::routers::{Router, RouterResponse}; -use crate::server::RouterError; +use crate::extractors::notification::Notification; +use crate::routers::{Router, RouterError, RouterResponse}; use async_trait::async_trait; use autopush_common::db::{DynamoDbUser, DynamoStorage}; use cadence::{Counted, StatsdClient}; diff --git a/autoendpoint/src/server/routes/health.rs b/autoendpoint/src/routes/health.rs similarity index 94% rename from autoendpoint/src/server/routes/health.rs rename to autoendpoint/src/routes/health.rs index 5cc5f9662..47c8447cf 100644 --- a/autoendpoint/src/server/routes/health.rs +++ b/autoendpoint/src/routes/health.rs @@ -32,5 +32,5 @@ pub fn version_route() -> HttpResponse { // and stored in the docker root HttpResponse::Ok() .content_type("application/json") - .body(include_str!("../../../../version.json")) + .body(include_str!("../../../version.json")) } diff --git a/autoendpoint/src/server/routes/mod.rs b/autoendpoint/src/routes/mod.rs similarity index 100% rename from autoendpoint/src/server/routes/mod.rs rename to autoendpoint/src/routes/mod.rs diff --git a/autoendpoint/src/server/routes/webpush.rs b/autoendpoint/src/routes/webpush.rs similarity index 79% rename from autoendpoint/src/server/routes/webpush.rs rename to autoendpoint/src/routes/webpush.rs index 80c8d5679..18bea4fdd 100644 --- a/autoendpoint/src/server/routes/webpush.rs +++ b/autoendpoint/src/routes/webpush.rs @@ -1,6 +1,6 @@ use crate::error::ApiResult; -use crate::server::extractors::notification::Notification; -use crate::server::extractors::routers::Routers; +use crate::extractors::notification::Notification; +use crate::extractors::routers::Routers; use actix_web::HttpResponse; /// Handle the `/wpush/{api_version}/{token}` and `/wpush/{token}` routes diff --git a/autoendpoint/src/server/mod.rs b/autoendpoint/src/server.rs similarity index 87% rename from autoendpoint/src/server/mod.rs rename to autoendpoint/src/server.rs index a1ef5371f..0d9b7690e 100644 --- a/autoendpoint/src/server/mod.rs +++ b/autoendpoint/src/server.rs @@ -2,11 +2,9 @@ use crate::error::{ApiError, ApiErrorKind, ApiResult}; use crate::metrics; -use crate::server::routers::fcm::router::FcmRouter; -use crate::server::routes::health::{ - health_route, lb_heartbeat_route, status_route, version_route, -}; -use crate::server::routes::webpush::webpush_route; +use crate::routers::fcm::router::FcmRouter; +use crate::routes::health::{health_route, lb_heartbeat_route, status_route, version_route}; +use crate::routes::webpush::webpush_route; use crate::settings::Settings; use actix_cors::Cors; use actix_web::{ @@ -17,15 +15,6 @@ use cadence::StatsdClient; use fernet::MultiFernet; use std::sync::Arc; -mod extractors; -mod headers; -mod routers; -mod routes; - -pub use headers::vapid::VapidError; -pub use routers::fcm::settings::FcmSettings; -pub use routers::RouterError; - #[derive(Clone)] pub struct ServerState { /// Server Data diff --git a/autoendpoint/src/settings.rs b/autoendpoint/src/settings.rs index 6bc2915e1..96f8111ca 100644 --- a/autoendpoint/src/settings.rs +++ b/autoendpoint/src/settings.rs @@ -1,6 +1,6 @@ //! Application settings -use crate::server::FcmSettings; +use crate::routers::fcm::settings::FcmSettings; use config::{Config, ConfigError, Environment, File}; use fernet::{Fernet, MultiFernet}; use serde::Deserialize;