Switched to yaml-based config

pull/36/head
Jef Roosens 2021-08-30 14:27:54 +02:00
parent 02011e04ce
commit 3cf7661faf
Signed by: Jef Roosens
GPG Key ID: B580B976584B5F30
5 changed files with 62 additions and 14 deletions

35
Cargo.lock generated
View File

@ -296,6 +296,12 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"
[[package]]
name = "dtoa"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0"
[[package]] [[package]]
name = "either" name = "either"
version = "1.6.1" version = "1.6.1"
@ -320,6 +326,7 @@ dependencies = [
"atomic", "atomic",
"pear", "pear",
"serde", "serde",
"serde_yaml",
"toml", "toml",
"uncased", "uncased",
"version_check", "version_check",
@ -641,6 +648,12 @@ version = "0.2.99"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7f823d141fe0a24df1e23b4af4e3c7ba9e5966ec514ea068c93024aa7deb765" checksum = "a7f823d141fe0a24df1e23b4af4e3c7ba9e5966ec514ea068c93024aa7deb765"
[[package]]
name = "linked-hash-map"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3"
[[package]] [[package]]
name = "lock_api" name = "lock_api"
version = "0.4.4" version = "0.4.4"
@ -1185,6 +1198,7 @@ dependencies = [
"chrono", "chrono",
"diesel", "diesel",
"diesel_migrations", "diesel_migrations",
"figment",
"hmac", "hmac",
"jwt", "jwt",
"openssl", "openssl",
@ -1270,6 +1284,18 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "serde_yaml"
version = "0.8.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "039ba818c784248423789eec090aab9fb566c7b94d6ebbfa1814a9fd52c8afb2"
dependencies = [
"dtoa",
"linked-hash-map",
"serde",
"yaml-rust",
]
[[package]] [[package]]
name = "sha1" name = "sha1"
version = "0.6.0" version = "0.6.0"
@ -1738,6 +1764,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "yaml-rust"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
dependencies = [
"linked-hash-map",
]
[[package]] [[package]]
name = "yansi" name = "yansi"
version = "0.5.0" version = "0.5.0"

View File

@ -34,6 +34,8 @@ sha2 = "*"
chrono = { version = "*", features = [ "serde" ] } chrono = { version = "*", features = [ "serde" ] }
# Encoding of refresh tokens # Encoding of refresh tokens
base64 = "0.13.0" base64 = "0.13.0"
# Reading in configuration files
figment = { version = "*", features = [ "yaml" ] }
[profile.release] [profile.release]
lto = true lto = true

19
Rb.yaml 100644
View File

@ -0,0 +1,19 @@
default:
address: "0.0.0.0"
ports: 8000
debug:
keep_alive: 5
read_timeout: 5
write_timeout: 5
log_level: "normal"
limits:
forms: 32768
admin_user: "admin"
admin_pass: "password"
jwt_key: "secret"
databases:
postgres_rb:
url: "postgres://rb:rb@localhost:5432/rb"

View File

@ -1,13 +0,0 @@
[debug]
port = 8000
keep_alive = 5
read_timeout = 5
write_timeout = 5
log_level = "normal"
limits = { forms = 32768 }
[debug.databases]
postgres_rb = { url = "postgres://rb:rb@localhost:5432/rb" }
[release.databases]
postgres_rb = { url = "postgres://rb:rb@localhost:5432/rb" }

View File

@ -10,6 +10,7 @@ extern crate diesel;
use rocket::{fairing::AdHoc, Build, Rocket}; use rocket::{fairing::AdHoc, Build, Rocket};
use rocket_sync_db_pools::database; use rocket_sync_db_pools::database;
use figment::{Figment, providers::Env, providers::Yaml, providers::Format};
mod admin; mod admin;
pub mod auth; pub mod auth;
@ -63,7 +64,11 @@ async fn create_admin_user(rocket: Rocket<Build>) -> Result<Rocket<Build>, Rocke
#[launch] #[launch]
fn rocket() -> _ fn rocket() -> _
{ {
rocket::build() let figment = Figment::from(rocket::config::Config::default())
.merge(Yaml::file("Rb.yaml").nested())
.merge(Env::prefixed("RB_").global());
rocket::custom(figment)
.attach(RbDbConn::fairing()) .attach(RbDbConn::fairing())
.attach(AdHoc::try_on_ignite( .attach(AdHoc::try_on_ignite(
"Run database migrations", "Run database migrations",