move rss key to config file

This commit is contained in:
philipp 2023-05-30 14:12:08 +02:00
parent 70e3d7524d
commit 14fd04a467
3 changed files with 12 additions and 6 deletions

View File

@ -17,7 +17,6 @@
- [] exactly same time -> deny registration - [] exactly same time -> deny registration
- [] automatically add regular planned trip - [] automatically add regular planned trip
- [] User sync w/ nextcloud - [] User sync w/ nextcloud
- [] remove key from src/rest/admin/rss.rs (line 8); at least before putting code somewhere public
- [] Rocket tests for /rest - [] Rocket tests for /rest
- [] same day+time: aggregate stats (x people, of which y cox and z rower) - [] same day+time: aggregate stats (x people, of which y cox and z rower)

View File

@ -1,17 +1,15 @@
use rocket::{get, routes, Route, State}; use rocket::{get, routes, Route, State};
use sqlx::SqlitePool; use sqlx::SqlitePool;
use crate::model::log::Log; use crate::{model::log::Log, rest::Config};
pub mod planned_event; pub mod planned_event;
pub mod user; pub mod user;
#[get("/rss?<key>")] #[get("/rss?<key>")]
async fn rss(db: &State<SqlitePool>, key: Option<&str>) -> String { async fn rss(db: &State<SqlitePool>, key: Option<&str>, config: &State<Config>) -> String {
match key { match key {
Some(key) if key.eq("G9h/f2MFEr408IaB4Yd67/maVSsnAJNjcaZ2Tzl5Vo=") => { Some(key) if key.eq(&config.rss_key) => Log::generate_feed(db).await,
Log::generate_feed(db).await
}
_ => "Not allowed".to_string(), _ => "Not allowed".to_string(),
} }
} }

View File

@ -1,6 +1,7 @@
use chrono::{Datelike, Duration, Local, NaiveDate}; use chrono::{Datelike, Duration, Local, NaiveDate};
use rocket::{ use rocket::{
catch, catchers, catch, catchers,
fairing::AdHoc,
fs::FileServer, fs::FileServer,
get, get,
request::FlashMessage, request::FlashMessage,
@ -8,6 +9,7 @@ use rocket::{
routes, Build, Rocket, State, routes, Build, Rocket, State,
}; };
use rocket_dyn_templates::{tera::Context, Template}; use rocket_dyn_templates::{tera::Context, Template};
use serde::Deserialize;
use sqlx::SqlitePool; use sqlx::SqlitePool;
use crate::model::{ use crate::model::{
@ -135,6 +137,12 @@ fn unauthorized_error() -> Redirect {
Redirect::to("/auth") Redirect::to("/auth")
} }
#[derive(Deserialize)]
#[serde(crate = "rocket::serde")]
pub struct Config {
rss_key: String,
}
pub fn start(db: SqlitePool) -> Rocket<Build> { pub fn start(db: SqlitePool) -> Rocket<Build> {
rocket::build() rocket::build()
.manage(db) .manage(db)
@ -146,6 +154,7 @@ pub fn start(db: SqlitePool) -> Rocket<Build> {
.mount("/public", FileServer::from("static/")) .mount("/public", FileServer::from("static/"))
.register("/", catchers![unauthorized_error]) .register("/", catchers![unauthorized_error])
.attach(Template::fairing()) .attach(Template::fairing())
.attach(AdHoc::config::<Config>())
} }
//#[cfg(test)] //#[cfg(test)]