From: Dessalines Date: Wed, 2 Sep 2020 23:17:35 +0000 (-0500) Subject: Adding rate_limiter and api_structs. X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/%7BpictshareAvatarThumbnail%28admin.avatar%29%7D?a=commitdiff_plain;h=3a6982e7b2aa8057f69633a01d69608c4392bfa0;p=lemmy.git Adding rate_limiter and api_structs. --- diff --git a/docker/dev/Dockerfile b/docker/dev/Dockerfile index 9bd74da0..dce2dc5b 100644 --- a/docker/dev/Dockerfile +++ b/docker/dev/Dockerfile @@ -20,12 +20,18 @@ RUN USER=root cargo new server # Install cargo-build-deps RUN cargo install --git https://github.com/romac/cargo-build-deps.git WORKDIR /app/server -RUN mkdir -p lemmy_db/src/ lemmy_utils/src/ +RUN mkdir -p lemmy_db/src/ \ + lemmy_utils/src/ \ + lemmy_api_structs/src/ \ + lemmy_rate_limit/src/ \ + lemmy # Copy the cargo tomls COPY server/Cargo.toml server/Cargo.lock ./ COPY server/lemmy_db/Cargo.toml ./lemmy_db/ COPY server/lemmy_utils/Cargo.toml ./lemmy_utils/ +COPY server/lemmy_api_structs/Cargo.toml ./lemmy_api_structs/ +COPY server/lemmy_rate_limit/Cargo.toml ./lemmy_rate_limit/ # Cache the deps RUN cargo build-deps @@ -34,6 +40,8 @@ RUN cargo build-deps COPY server/src ./src/ COPY server/lemmy_db/src ./lemmy_db/src/ COPY server/lemmy_utils/src/ ./lemmy_utils/src/ +COPY server/lemmy_api_structs/src/ ./lemmy_api_structs/src/ +COPY server/lemmy_rate_limit/src/ ./lemmy_rate_limit/src/ COPY server/migrations ./migrations/ # Build for debug diff --git a/docker/prod/Dockerfile b/docker/prod/Dockerfile index 845df88d..9bccb448 100644 --- a/docker/prod/Dockerfile +++ b/docker/prod/Dockerfile @@ -13,6 +13,8 @@ WORKDIR /app/server COPY server/Cargo.toml server/Cargo.lock ./ COPY server/lemmy_db ./lemmy_db COPY server/lemmy_utils ./lemmy_utils +COPY server/lemmy_api_structs ./lemmy_api_structs +COPY server/lemmy_rate_limit ./lemmy_rate_limit RUN mkdir -p ./src/bin \ && echo 'fn main() { println!("Dummy") }' > ./src/bin/main.rs RUN cargo build --release diff --git a/server/Cargo.toml b/server/Cargo.toml index 912d130d..e12d8c61 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -11,6 +11,7 @@ members = [ "lemmy_utils", "lemmy_db", "lemmy_api_structs", + "lemmy_rate_limit", ] [dependencies] diff --git a/server/lemmy_api_structs/Cargo.toml b/server/lemmy_api_structs/Cargo.toml index d1695eca..93653fba 100644 --- a/server/lemmy_api_structs/Cargo.toml +++ b/server/lemmy_api_structs/Cargo.toml @@ -4,6 +4,10 @@ version = "0.1.0" authors = ["Felix Ableitner "] edition = "2018" +[lib] +name = "lemmy_api_structs" +path = "src/lib.rs" + [dependencies] lemmy_db = { path = "../lemmy_db" } serde = { version = "1.0.105", features = ["derive"] } diff --git a/server/lemmy_rate_limit/Cargo.toml b/server/lemmy_rate_limit/Cargo.toml index 4fc65254..001297fc 100644 --- a/server/lemmy_rate_limit/Cargo.toml +++ b/server/lemmy_rate_limit/Cargo.toml @@ -4,6 +4,10 @@ version = "0.1.0" authors = ["Felix Ableitner "] edition = "2018" +[lib] +name = "lemmy_rate_limit" +path = "src/lib.rs" + [dependencies] lemmy_utils = { path = "../lemmy_utils" } lemmy_api_structs = { path = "../lemmy_api_structs" } diff --git a/server/lemmy_rate_limit/src/lib.rs b/server/lemmy_rate_limit/src/lib.rs index 431a2d76..2d3553f0 100644 --- a/server/lemmy_rate_limit/src/lib.rs +++ b/server/lemmy_rate_limit/src/lib.rs @@ -1,13 +1,17 @@ #[macro_use] pub extern crate strum_macros; -pub extern crate tokio; -pub extern crate futures; pub extern crate actix_web; +pub extern crate futures; pub extern crate log; +pub extern crate tokio; use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform}; use futures::future::{ok, Ready}; -use lemmy_utils::settings::{RateLimitConfig, Settings}; +use lemmy_utils::{ + get_ip, + settings::{RateLimitConfig, Settings}, + LemmyError, +}; use rate_limiter::{RateLimitType, RateLimiter}; use std::{ future::Future, @@ -16,8 +20,6 @@ use std::{ task::{Context, Poll}, }; use tokio::sync::Mutex; -use lemmy_utils::get_ip; -use lemmy_utils::LemmyError; pub mod rate_limiter; diff --git a/server/lemmy_rate_limit/src/rate_limiter.rs b/server/lemmy_rate_limit/src/rate_limiter.rs index 1c90f90e..b4854729 100644 --- a/server/lemmy_rate_limit/src/rate_limiter.rs +++ b/server/lemmy_rate_limit/src/rate_limiter.rs @@ -1,6 +1,5 @@ -use lemmy_utils::IPAddr; -use lemmy_utils::LemmyError; use lemmy_api_structs::APIError; +use lemmy_utils::{IPAddr, LemmyError}; use log::debug; use std::{collections::HashMap, time::SystemTime}; use strum::IntoEnumIterator; diff --git a/server/lemmy_utils/src/lib.rs b/server/lemmy_utils/src/lib.rs index 97f32f27..20509343 100644 --- a/server/lemmy_utils/src/lib.rs +++ b/server/lemmy_utils/src/lib.rs @@ -1,5 +1,7 @@ #[macro_use] pub extern crate lazy_static; +pub extern crate actix_web; +pub extern crate anyhow; pub extern crate comrak; pub extern crate lettre; pub extern crate lettre_email; @@ -8,12 +10,11 @@ pub extern crate rand; pub extern crate regex; pub extern crate serde_json; pub extern crate url; -pub extern crate actix_web; -pub extern crate anyhow; pub mod settings; use crate::settings::Settings; +use actix_web::dev::ConnectionInfo; use chrono::{DateTime, FixedOffset, Local, NaiveDateTime}; use itertools::Itertools; use lettre::{ @@ -32,7 +33,6 @@ use rand::{distributions::Alphanumeric, thread_rng, Rng}; use regex::{Regex, RegexBuilder}; use std::io::{Error, ErrorKind}; use url::Url; -use actix_web::dev::ConnectionInfo; pub type ConnectionId = usize; pub type PostId = i32; @@ -58,8 +58,8 @@ pub struct LemmyError { } impl From for LemmyError - where - T: Into, +where + T: Into, { fn from(t: T) -> Self { LemmyError { inner: t.into() } @@ -386,4 +386,4 @@ pub fn get_ip(conn_info: &ConnectionInfo) -> String { .next() .unwrap_or("127.0.0.1") .to_string() -} \ No newline at end of file +}