2022-02-21 18:57:40 -08:00
|
|
|
use actix_web::guard::GuardContext;
|
|
|
|
|
|
|
|
|
|
pub const ADMIN_KEY_HEADER: &str = "Modrinth-Admin";
|
2025-08-11 17:40:58 -04:00
|
|
|
pub const MEDAL_KEY_HEADER: &str = "X-Medal-Access-Key";
|
|
|
|
|
|
2022-02-21 18:57:40 -08:00
|
|
|
pub fn admin_key_guard(ctx: &GuardContext) -> bool {
|
2024-10-18 16:07:35 -07:00
|
|
|
let admin_key = std::env::var("LABRINTH_ADMIN_KEY").expect(
|
|
|
|
|
"No admin key provided, this should have been caught by check_env_vars",
|
|
|
|
|
);
|
2022-02-21 18:57:40 -08:00
|
|
|
ctx.head()
|
|
|
|
|
.headers()
|
|
|
|
|
.get(ADMIN_KEY_HEADER)
|
2025-01-16 16:40:13 -08:00
|
|
|
.is_some_and(|it| it.as_bytes() == admin_key.as_bytes())
|
2022-02-21 18:57:40 -08:00
|
|
|
}
|
2025-08-11 17:40:58 -04:00
|
|
|
|
|
|
|
|
pub fn medal_key_guard(ctx: &GuardContext) -> bool {
|
|
|
|
|
let maybe_medal_key = dotenvy::var("LABRINTH_MEDAL_KEY").ok();
|
|
|
|
|
|
|
|
|
|
match maybe_medal_key {
|
|
|
|
|
None => false,
|
|
|
|
|
Some(medal_key) => ctx
|
|
|
|
|
.head()
|
|
|
|
|
.headers()
|
|
|
|
|
.get(MEDAL_KEY_HEADER)
|
|
|
|
|
.is_some_and(|it| it.as_bytes() == medal_key.as_bytes()),
|
|
|
|
|
}
|
|
|
|
|
}
|