Browse Source

Fix some bugs

Made some changes to the fairings to fix some major bugs

closes #63
partially fixes #62
master
Steven vanZyl 3 weeks ago
parent
commit
9154d51939
2 changed files with 13 additions and 7 deletions
  1. 1
    1
      Rocket.toml
  2. 12
    6
      src/fairings.rs

+ 1
- 1
Rocket.toml View File

@@ -11,7 +11,7 @@ databases = { sqlite_observ = { url = "./observ.sqlite" } }
11 11
 address = "0.0.0.0"
12 12
 port = 8000
13 13
 log = "critical"
14
-databases = { sqlite_observ = { url = "/var/lib/observatory/observ.sqlite" } }
14
+databases = { sqlite_observ = { url = "/var/lib/observatory/observ.sqlite", pool_size = 20 } }
15 15
 # Make sure to generate a secret key using:
16 16
 # `$ openssl rand -base64 32`
17 17
 # Put it here replacing the placeholder and uncomment

+ 12
- 6
src/fairings.rs View File

@@ -148,9 +148,6 @@ impl Fairing for ConfigWrite {
148 148
         }
149 149
 
150 150
         println!("\tRocket.toml does not exist, generating...");
151
-        println!(
152
-            "\tWARNING: If you set your secret_key via enviroment variable it will be overwritten!"
153
-        );
154 151
 
155 152
         conf.set_root(".");
156 153
 
@@ -190,12 +187,21 @@ impl Fairing for ConfigWrite {
190 187
 
191 188
         // If in production mode generate and set a secret key
192 189
         let s = if rocket.config().environment.is_prod() {
193
-            // Generate a new secret key
194
-            let s = gen_secret();
190
+            // Check if there was an environment variable one
191
+            let s = if let Some((_, value)) = std::env::vars().find(|(k, _)| k == "ROCKET_SECRET_KEY") {
192
+                println!("\tUsing secret key from ROCKET_SECRET_KEY environment variable");
193
+                value 
194
+            } else {
195
+                // Generate a new secret key
196
+                println!("\tGenerating new secret key");
197
+                gen_secret()
198
+            };
195 199
             // Set the key in the config
196 200
             conf.set_secret_key(s.clone()).unwrap();
197 201
             s
198 202
         } else {
203
+            // If we're not in production mode we don't care about
204
+            // the secret key so just use a blank string
199 205
             String::new()
200 206
         };
201 207
         // Write the config with the key to a file
@@ -235,7 +241,7 @@ fn write_config(conf: &rocket::Config, secret: &String) -> std::io::Result<()> {
235 241
 
236 242
     // Get the extra fields like the databases and add them
237 243
     outstring += &format!(
238
-        "databases = {{ sqlite_observ = {{ url = {} }} }}",
244
+        "databases = {{ sqlite_observ = {{ url = \"{}\", pool_size = 20 }} }}",
239 245
         conf.extras
240 246
             .get("databases")
241 247
             .unwrap()

Loading…
Cancel
Save