Skip to content

Commit dc81f4b

Browse files
committed
Extract request_filter and dsc_webhook crates
* Extract the request_filter module from the game_api crate to a proper crate, for better responsibility separation architecture * Extract the discord_webhook module from the game_api crate to a proper dsc_webhook crate, because it was needed by both game_api and newest request_filter crate. * Remove records-lib workspace dependency (use path instead in each workspace crate)
1 parent 61830c8 commit dc81f4b

File tree

18 files changed

+98
-87
lines changed

18 files changed

+98
-87
lines changed

Cargo.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
[workspace]
22
resolver = "2"
33
members = [
4-
"crates/game_api",
5-
"crates/records_lib",
6-
"crates/socc",
7-
"crates/admin",
4+
"crates/game_api",
5+
"crates/records_lib",
6+
"crates/socc",
7+
"crates/admin",
8+
"crates/request_filter",
9+
"crates/dsc_webhook",
810
]
911

1012
[workspace.dependencies]
@@ -33,5 +35,5 @@ itertools = "0.14.0"
3335
once_cell = "1.21.1"
3436
csv = "1.3.0"
3537
mkenv = "0.1.6"
36-
records-lib = { version = "1", path = "./crates/records_lib" }
3738
nom = "8.0.0"
39+
pin-project-lite = "0.2.16"

crates/admin/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ deadpool-redis = { workspace = true }
1111
dotenvy = { workspace = true }
1212
futures = { workspace = true }
1313
itertools = { workspace = true }
14-
records-lib = { workspace = true, features = ["tracing"] }
14+
records-lib = { path = "../records_lib", features = ["tracing"] }
1515
reqwest = { workspace = true }
1616
serde = { workspace = true }
1717
sqlx = { workspace = true }

crates/dsc_webhook/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "dsc_webhook"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
serde = { workspace = true }

crates/game_api/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ anyhow = { workspace = true }
3333
dotenvy = { workspace = true }
3434
itertools = { workspace = true }
3535
once_cell = { workspace = true }
36-
records-lib = { workspace = true, features = ["tracing"] }
36+
records-lib = { path = "../records_lib", features = ["tracing"] }
3737
mkenv = { workspace = true }
3838
nom = { workspace = true }
3939
pin-project-lite = { version = "0.2.16", optional = true }
40+
request_filter = { path = "../request_filter", optional = true }
41+
dsc_webhook = { path = "../dsc_webhook" }
4042

4143
[features]
4244
default = ["request_filter"]
4345
gql_schema = []
44-
request_filter = ["dep:pin-project-lite"]
46+
request_filter = ["dep:pin-project-lite", "dep:request_filter"]
4547
auth = []

crates/game_api/src/env.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use mkenv::{Env as _, EnvSplitIncluded as _};
22
use once_cell::sync::OnceCell;
33
use records_lib::{DbEnv, LibEnv};
4+
use tracing::instrument::WithSubscriber;
45

56
#[cfg(test)]
67
const DEFAULT_SESSION_KEY: &str = "";
@@ -21,7 +22,15 @@ mkenv::make_env! {pub ApiEnvUsedOnce:
2122
var: "RECORDS_API_SESSION_KEY",
2223
desc: "The session key used by the API",
2324
default: DEFAULT_SESSION_KEY,
24-
}
25+
},
26+
27+
wh_invalid_req_url: {
28+
id: WebhookInvalidReqUrl(String),
29+
kind: normal,
30+
var: "WEBHOOK_INVALID_REQ_URL",
31+
desc: "The URL to the Discord webhook used to flag invalid requests",
32+
default: DEFAULT_WH_INVALID_REQ_URL,
33+
},
2534
}
2635

2736
const DEFAULT_PORT: u16 = 3000;
@@ -112,14 +121,6 @@ mkenv::make_env! {pub ApiEnv includes [
112121
default: DEFAULT_WH_AC_URL,
113122
},
114123

115-
wh_invalid_req_url: {
116-
id: WebhookInvalidReqUrl(String),
117-
kind: normal,
118-
var: "WEBHOOK_INVALID_REQ_URL",
119-
desc: "The URL to the Discord webhook used to flag invalid requests",
120-
default: DEFAULT_WH_INVALID_REQ_URL,
121-
},
122-
123124
gql_endpoint: {
124125
id: GqlEndpoint(String),
125126
kind: normal,

crates/game_api/src/http.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ use self::event::event_scope;
1717
use self::map::map_scope;
1818
use self::player::player_scope;
1919
use self::staggered::staggered_scope;
20-
use crate::discord_webhook::{WebhookBody, WebhookBodyEmbed, WebhookBodyEmbedField};
21-
#[cfg(feature = "request_filter")]
22-
use crate::request_filter::{FlagFalseRequest, InGameFilter};
2320
use crate::utils::{self, ApiStatus, get_api_status, json};
2421
use crate::{FitRequestId as _, ModeVersion, RecordsResponse, RecordsResultExt, Res};
2522
use actix_web::Responder;
23+
use dsc_webhook::{WebhookBody, WebhookBodyEmbed, WebhookBodyEmbedField};
24+
#[cfg(feature = "request_filter")]
25+
use request_filter::{FlagFalseRequest, InGameFilter};
2626

2727
#[cfg(auth)]
2828
pub mod admin;

crates/game_api/src/http/player.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ use crate::{
3737
use crate::{
3838
FitRequestId as _, RecordsErrorKind, RecordsResponse, RecordsResult, RecordsResultExt, Res,
3939
auth::{self, ApiAvailable, AuthHeader, MPAuthGuard, privilege},
40-
discord_webhook::{WebhookBody, WebhookBodyEmbed, WebhookBodyEmbedField},
4140
utils::{self, json},
4241
};
42+
use dsc_webhook::{WebhookBody, WebhookBodyEmbed, WebhookBodyEmbedField};
4343

4444
#[cfg(feature = "request_filter")]
45-
use crate::request_filter::{FlagFalseRequest, WebsiteFilter};
45+
use request_filter::{FlagFalseRequest, WebsiteFilter};
4646

4747
use super::{
4848
pb,

crates/game_api/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
pub use deadpool_redis::Pool as RedisPool;
66
pub use sqlx::MySqlPool;
77

8-
mod request_filter;
9-
108
mod auth;
11-
mod discord_webhook;
129
mod env;
1310
mod error;
1411
mod graphql;

crates/game_api/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ async fn not_found(req_id: RequestId) -> RecordsResponse<impl Responder> {
5454
async fn main() -> anyhow::Result<()> {
5555
dotenvy::dotenv()?;
5656
let env = game_api_lib::init_env()?;
57+
#[cfg(feature = "request_filter")]
58+
request_filter::init_wh_url(env.used_once.wh_invalid_req_url)
59+
.unwrap_or_else(|_| panic!("Invalid request WH URL isn't supposed to be set twice"));
5760

5861
let mysql_pool = get_mysql_pool(env.db_env.db_url.db_url)
5962
.await

0 commit comments

Comments
 (0)