From 288941e8a3c96bfcee858cffb71583a395909505 Mon Sep 17 00:00:00 2001 From: notplants Date: Thu, 12 May 2022 11:26:23 +0200 Subject: [PATCH] Change Rouille to use get_config_value --- Cargo.lock | 2 +- peach-config/Cargo.toml | 2 +- peach-lib/src/config_manager.rs | 2 +- peach-web/src/config.rs | 17 +++++++++-------- peach-web/src/main.rs | 8 ++++---- peach-web/src/routes/settings/menu.rs | 4 ++-- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 40d86d4..02a0593 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2386,7 +2386,7 @@ dependencies = [ [[package]] name = "peach-config" -version = "0.1.23" +version = "0.1.24" dependencies = [ "clap", "env_logger 0.6.2", diff --git a/peach-config/Cargo.toml b/peach-config/Cargo.toml index 679d4d9..d51afdb 100644 --- a/peach-config/Cargo.toml +++ b/peach-config/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "peach-config" -version = "0.1.23" +version = "0.1.24" authors = ["Andrew Reid ", "Max Fowler "] edition = "2018" description = "Command line tool for installing, updating and configuring PeachCloud" diff --git a/peach-lib/src/config_manager.rs b/peach-lib/src/config_manager.rs index 840b11b..a3213f6 100644 --- a/peach-lib/src/config_manager.rs +++ b/peach-lib/src/config_manager.rs @@ -57,7 +57,7 @@ pub fn get_peach_config_defaults() -> HashMap { ("DYN_NAMESERVER", "ns.peachcloud.org"), ("DYN_ENABLED", "false"), ("SSB_ADMIN_IDS", ""), - ("ADMIN_PASSWORD_HASH", "146"), + ("ADMIN_PASSWORD_HASH", "47"), ("TEMPORARY_PASSWORD_HASH", ""), ("GO_SBOT_DATADIR", ""), ("PEACH_CONFIGDIR", "/var/lib/peachcloud"), diff --git a/peach-web/src/config.rs b/peach-web/src/config.rs index b1c2e95..385404b 100644 --- a/peach-web/src/config.rs +++ b/peach-web/src/config.rs @@ -4,18 +4,19 @@ //! variables have been set. use std::env; +use peach_lib::config_manager::get_config_value; // environment variable keys to check for -const ENV_VARS: [&str; 4] = ["STANDALONE_MODE", "DISABLE_AUTH", "ADDR", "PORT"]; +const CONFIG_KEYS: [&str; 4] = ["STANDALONE_MODE", "DISABLE_AUTH", "ADDR", "PORT"]; -pub struct Config { +pub struct RouilleConfig { pub standalone_mode: bool, pub disable_auth: bool, pub addr: String, pub port: String, } -impl Default for Config { +impl Default for RouilleConfig { fn default() -> Self { Self { standalone_mode: true, @@ -26,15 +27,15 @@ impl Default for Config { } } -impl Config { - pub fn new() -> Config { +impl RouilleConfig { + pub fn new() -> RouilleConfig { // define default config values - let mut config = Config::default(); + let mut config = RouilleConfig::default(); // check for the environment variables in our config - for key in ENV_VARS { + for key in CONFIG_KEYS { // if a variable (key) has been set, check the value - if let Ok(val) = env::var(key) { + if let Ok(val) = get_config_value(key) { // if the value is of the correct type, update the config value match key { "STANDALONE_MODE" if val.as_str() == "true" => config.standalone_mode = true, diff --git a/peach-web/src/main.rs b/peach-web/src/main.rs index b43d669..ee2f1de 100644 --- a/peach-web/src/main.rs +++ b/peach-web/src/main.rs @@ -29,12 +29,12 @@ use lazy_static::lazy_static; use log::info; // crate-local dependencies -use config::Config; +use config::RouilleConfig; use utils::theme::Theme; // load the application configuration and create the theme switcher lazy_static! { - static ref CONFIG: Config = Config::new(); + static ref ROUILLE_CONFIG: RouilleConfig = RouilleConfig::new(); static ref THEME: RwLock = RwLock::new(Theme::Light); } @@ -51,7 +51,7 @@ fn main() { // set ip address / hostname and port for the webserver // defaults to "127.0.0.1:8000" - let addr_and_port = format!("{}:{}", CONFIG.addr, CONFIG.port); + let addr_and_port = format!("{}:{}", ROUILLE_CONFIG.addr, ROUILLE_CONFIG.port); // store the session data for each session and a hashmap that associates // each session id with the data @@ -67,7 +67,7 @@ fn main() { // with a name of "SID" and a duration of one hour (3600 seconds) rouille::session::session(request, "SID", 3600, |session| { // if the "DISABLE_AUTH" env var is true, authenticate the session - let mut session_data = if CONFIG.disable_auth { + let mut session_data = if ROUILLE_CONFIG.disable_auth { Some(SessionData { _login: "success".to_string(), }) diff --git a/peach-web/src/routes/settings/menu.rs b/peach-web/src/routes/settings/menu.rs index c49218d..6745263 100644 --- a/peach-web/src/routes/settings/menu.rs +++ b/peach-web/src/routes/settings/menu.rs @@ -1,6 +1,6 @@ use maud::{html, PreEscaped}; -use crate::{templates, utils::theme, CONFIG}; +use crate::{templates, utils::theme, ROUILLE_CONFIG}; // ROUTE: /settings @@ -12,7 +12,7 @@ pub fn build_template() -> PreEscaped { (PreEscaped("")) div id="settingsButtons" { // render the network settings button if we're not in standalone mode - @if !CONFIG.standalone_mode { + @if !ROUILLE_CONFIG.standalone_mode { a id="network" class="button button-primary center" href="/settings/network" title="Network Settings" { "Network" } } a id="scuttlebutt" class="button button-primary center" href="/settings/scuttlebutt" title="Scuttlebutt Settings" { "Scuttlebutt" }