Merge pull request 'Use get_config_value for Rouille configurations' (#109) from get-config into main
Reviewed-on: #109
This commit is contained in:
commit
4a08e4ed6d
|
@ -1111,7 +1111,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "golgi"
|
name = "golgi"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
source = "git+https://git.coopcloud.tech/golgi-ssb/golgi#77dd75bcd4649b7487069a61e2a8069b49f60a1d"
|
source = "git+https://git.coopcloud.tech/golgi-ssb/golgi.git#77dd75bcd4649b7487069a61e2a8069b49f60a1d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-std",
|
"async-std",
|
||||||
"async-stream 0.3.3",
|
"async-stream 0.3.3",
|
||||||
|
@ -2386,7 +2386,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "peach-config"
|
name = "peach-config"
|
||||||
version = "0.1.23"
|
version = "0.1.24"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"env_logger 0.6.2",
|
"env_logger 0.6.2",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "peach-config"
|
name = "peach-config"
|
||||||
version = "0.1.23"
|
version = "0.1.24"
|
||||||
authors = ["Andrew Reid <gnomad@cryptolab.net>", "Max Fowler <max@mfowler.info>"]
|
authors = ["Andrew Reid <gnomad@cryptolab.net>", "Max Fowler <max@mfowler.info>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Command line tool for installing, updating and configuring PeachCloud"
|
description = "Command line tool for installing, updating and configuring PeachCloud"
|
||||||
|
|
|
@ -57,7 +57,7 @@ pub fn get_peach_config_defaults() -> HashMap<String, String> {
|
||||||
("DYN_NAMESERVER", "ns.peachcloud.org"),
|
("DYN_NAMESERVER", "ns.peachcloud.org"),
|
||||||
("DYN_ENABLED", "false"),
|
("DYN_ENABLED", "false"),
|
||||||
("SSB_ADMIN_IDS", ""),
|
("SSB_ADMIN_IDS", ""),
|
||||||
("ADMIN_PASSWORD_HASH", "146"),
|
("ADMIN_PASSWORD_HASH", "47"),
|
||||||
("TEMPORARY_PASSWORD_HASH", ""),
|
("TEMPORARY_PASSWORD_HASH", ""),
|
||||||
("GO_SBOT_DATADIR", ""),
|
("GO_SBOT_DATADIR", ""),
|
||||||
("PEACH_CONFIGDIR", "/var/lib/peachcloud"),
|
("PEACH_CONFIGDIR", "/var/lib/peachcloud"),
|
||||||
|
|
|
@ -1,53 +1,31 @@
|
||||||
//! Define the configuration parameters for the web application.
|
//! Define the configuration parameters for the web application.
|
||||||
//!
|
//!
|
||||||
//! Sets default values and updates them if the corresponding environment
|
//! These configs are loaded using peach-lib::config_manager which checks config keys from
|
||||||
//! variables have been set.
|
//! three sources:
|
||||||
|
//! 1. from environmental variables
|
||||||
|
//! 2. from a configuration file
|
||||||
|
//! 3. from default values
|
||||||
|
|
||||||
use std::env;
|
use crate::error::PeachWebError;
|
||||||
|
use peach_lib::config_manager::get_config_value;
|
||||||
|
|
||||||
// environment variable keys to check for
|
pub struct ServerConfig {
|
||||||
const ENV_VARS: [&str; 4] = ["STANDALONE_MODE", "DISABLE_AUTH", "ADDR", "PORT"];
|
|
||||||
|
|
||||||
pub struct Config {
|
|
||||||
pub standalone_mode: bool,
|
pub standalone_mode: bool,
|
||||||
pub disable_auth: bool,
|
pub disable_auth: bool,
|
||||||
pub addr: String,
|
pub addr: String,
|
||||||
pub port: String,
|
pub port: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Config {
|
impl ServerConfig {
|
||||||
fn default() -> Self {
|
pub fn new() -> Result<ServerConfig, PeachWebError> {
|
||||||
Self {
|
|
||||||
standalone_mode: true,
|
|
||||||
disable_auth: false,
|
|
||||||
addr: "127.0.0.1".to_string(),
|
|
||||||
port: "8000".to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Config {
|
|
||||||
pub fn new() -> Config {
|
|
||||||
// define default config values
|
// define default config values
|
||||||
let mut config = Config::default();
|
let config = ServerConfig {
|
||||||
|
standalone_mode: get_config_value("STANDALONE_MODE")?.as_str() == "true",
|
||||||
|
disable_auth: get_config_value("DISABLE_AUTH")?.as_str() == "true",
|
||||||
|
addr: get_config_value("ADDR")?,
|
||||||
|
port: get_config_value("PORT")?,
|
||||||
|
};
|
||||||
|
|
||||||
// check for the environment variables in our config
|
Ok(config)
|
||||||
for key in ENV_VARS {
|
|
||||||
// if a variable (key) has been set, check the value
|
|
||||||
if let Ok(val) = env::var(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,
|
|
||||||
"STANDALONE_MODE" if val.as_str() == "false" => config.standalone_mode = false,
|
|
||||||
"DISABLE_AUTH" if val.as_str() == "true" => config.disable_auth = true,
|
|
||||||
"DISABLE_AUTH" if val.as_str() == "false" => config.disable_auth = false,
|
|
||||||
"ADDR" => config.addr = val,
|
|
||||||
"PORT" => config.port = val,
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
config
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,12 +29,13 @@ use lazy_static::lazy_static;
|
||||||
use log::info;
|
use log::info;
|
||||||
|
|
||||||
// crate-local dependencies
|
// crate-local dependencies
|
||||||
use config::Config;
|
use config::ServerConfig;
|
||||||
use utils::theme::Theme;
|
use utils::theme::Theme;
|
||||||
|
|
||||||
// load the application configuration and create the theme switcher
|
// load the application configuration and create the theme switcher
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref CONFIG: Config = Config::new();
|
static ref SERVER_CONFIG: ServerConfig =
|
||||||
|
ServerConfig::new().expect("Failed to load rouille configuration values on server startup");
|
||||||
static ref THEME: RwLock<Theme> = RwLock::new(Theme::Light);
|
static ref THEME: RwLock<Theme> = RwLock::new(Theme::Light);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ fn main() {
|
||||||
|
|
||||||
// set ip address / hostname and port for the webserver
|
// set ip address / hostname and port for the webserver
|
||||||
// defaults to "127.0.0.1:8000"
|
// defaults to "127.0.0.1:8000"
|
||||||
let addr_and_port = format!("{}:{}", CONFIG.addr, CONFIG.port);
|
let addr_and_port = format!("{}:{}", SERVER_CONFIG.addr, SERVER_CONFIG.port);
|
||||||
|
|
||||||
// store the session data for each session and a hashmap that associates
|
// store the session data for each session and a hashmap that associates
|
||||||
// each session id with the data
|
// each session id with the data
|
||||||
|
@ -67,7 +68,7 @@ fn main() {
|
||||||
// with a name of "SID" and a duration of one hour (3600 seconds)
|
// with a name of "SID" and a duration of one hour (3600 seconds)
|
||||||
rouille::session::session(request, "SID", 3600, |session| {
|
rouille::session::session(request, "SID", 3600, |session| {
|
||||||
// if the "DISABLE_AUTH" env var is true, authenticate the 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 SERVER_CONFIG.disable_auth {
|
||||||
Some(SessionData {
|
Some(SessionData {
|
||||||
_login: "success".to_string(),
|
_login: "success".to_string(),
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use maud::{html, PreEscaped};
|
use maud::{html, PreEscaped};
|
||||||
|
|
||||||
use crate::{templates, utils::theme, CONFIG};
|
use crate::{templates, utils::theme, SERVER_CONFIG};
|
||||||
|
|
||||||
// ROUTE: /settings
|
// ROUTE: /settings
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ pub fn build_template() -> PreEscaped<String> {
|
||||||
(PreEscaped("<!-- BUTTONS -->"))
|
(PreEscaped("<!-- BUTTONS -->"))
|
||||||
div id="settingsButtons" {
|
div id="settingsButtons" {
|
||||||
// render the network settings button if we're not in standalone mode
|
// render the network settings button if we're not in standalone mode
|
||||||
@if !CONFIG.standalone_mode {
|
@if !SERVER_CONFIG.standalone_mode {
|
||||||
a id="network" class="button button-primary center" href="/settings/network" title="Network Settings" { "Network" }
|
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" }
|
a id="scuttlebutt" class="button button-primary center" href="/settings/scuttlebutt" title="Scuttlebutt Settings" { "Scuttlebutt" }
|
||||||
|
|
Loading…
Reference in New Issue