From 6013d0bb6e318d6c40c113750adb11e79d5970d8 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Tue, 23 Nov 2021 18:00:10 +0100 Subject: [PATCH] Added correct config reading --- Rb.yaml | 41 +++++++++++++++++++++++++++++++++++++++++ src/main.rs | 17 +++++++++-------- src/sections.rs | 5 +---- 3 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 Rb.yaml diff --git a/Rb.yaml b/Rb.yaml new file mode 100644 index 0000000..8a3f881 --- /dev/null +++ b/Rb.yaml @@ -0,0 +1,41 @@ +default: + address: "0.0.0.0" + ports: 8000 + +debug: + keep_alive: 5 + read_timeout: 5 + write_timeout: 5 + log_level: "normal" + limits: + forms: 32768 + + jwt: + key: "secret" + refresh_token_size: 64 + # Just 5 seconds for debugging + refresh_token_expire: 60 + + databases: + postgres_rb: + url: "postgres://rb:rb@localhost:5433/rb" + +release: + keep_alive: 5 + read_timeout: 5 + write_timeout: 5 + log_level: "normal" + limits: + forms: 32768 + + admin_user: "admin" + admin_pass: "password" + jwt: + key: "secret" + refresh_token_size: 64 + # Just 5 seconds for debugging + refresh_token_expire: 60 + + databases: + postgres_rb: + url: "postgres://rb:rb@db:5432/rb" diff --git a/src/main.rs b/src/main.rs index d03c883..e0542eb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,7 @@ pub struct RbDbConn(diesel::PgConnection); #[catch(default)] fn default_catcher(status: Status, _: &Request) -> Value { - json!({"status": status.code, "message": ""}) + json!({"status": status.code, "message": "Not found."}) } embed_migrations!(); @@ -46,8 +46,6 @@ async fn run_db_migrations(rocket: Rocket) -> Result, Rocke #[derive(Debug, Deserialize, Serialize)] pub struct RbConfig { - admin_user: String, - admin_pass: String, jwt: JwtConf, } @@ -58,17 +56,20 @@ fn rocket() -> _ .merge(Yaml::file("Rb.yaml").nested()) .merge(Env::prefixed("RB_").global()); - // This mut is necessary when the "docs" or "web" feature is enabled, as these further modify - // the instance variable - rocket::custom(figment) + let rocket = rocket::custom(figment) .attach(RbDbConn::fairing()) .attach(AdHoc::try_on_ignite( "Run database migrations", run_db_migrations, )) // .attach(AdHoc::try_on_ignite("Create admin user", create_admin_user)) - .attach(AdHoc::config::()) + // .attach(AdHoc::config::()) .register("/", catchers![default_catcher]) .mount("/sections", routes![sections::create_section]) - .mount("/posts", routes![posts::get, posts::create]) + .mount("/posts", routes![posts::get, posts::create]); + + let new_figment = rocket.figment(); + let jwt_conf: JwtConf = new_figment.extract_inner("jwt").expect("jwt config"); + + rocket.manage(jwt_conf) } diff --git a/src/sections.rs b/src/sections.rs index efec631..2494045 100644 --- a/src/sections.rs +++ b/src/sections.rs @@ -1,9 +1,6 @@ //! This module handles management of site sections (aka blogs). -use rb::{ - errors::{RbOption, RbResult}, - guards::Admin, -}; +use rb::{errors::RbResult, guards::Admin}; use rb_blog::db; use rocket::serde::json::Json;