🔧 config (ptth_relay): add feature flags

- dev mode
- scraper auth

These will gate features I'm adding soon.
main
_ 2020-12-12 01:26:58 +00:00
parent 4014290f98
commit f6486b2c1a
4 changed files with 37 additions and 16 deletions

View File

@ -23,10 +23,22 @@ pub mod file {
pub display_name: Option <String>,
}
// Stuff that's identical between the file and the runtime structures
#[derive (Default, Deserialize)]
pub struct Isomorphic {
#[serde (default)]
pub enable_dev_mode: bool,
#[serde (default)]
pub enable_scraper_auth: bool,
}
#[derive (Deserialize)]
pub struct Config {
pub port: Option <u16>,
pub servers: Vec <Server>,
#[serde (flatten)]
pub iso: Isomorphic,
}
}
@ -39,6 +51,7 @@ pub struct Server {
pub struct Config {
pub servers: HashMap <String, Server>,
pub iso: file::Isomorphic,
}
impl TryFrom <file::Server> for Server {
@ -68,6 +81,7 @@ impl TryFrom <file::Config> for Config {
Ok (Self {
servers,
iso: f.iso,
})
}
}

View File

@ -495,6 +495,12 @@ async fn reload_config (
(*config) = new_config;
debug! ("Loaded {} server configs", config.servers.len ());
debug! ("enable_dev_mode: {}", config.iso.enable_dev_mode);
debug! ("enable_scraper_auth: {}", config.iso.enable_scraper_auth);
if config.iso.enable_dev_mode {
error! ("Dev mode is enabled! This might turn off some security features. If you see this in production, escalate it to someone!");
}
Ok (())
}

View File

@ -31,22 +31,22 @@ stronger is ready.
## Proposed impl plan
- Add feature flags to ptth_relay.toml for dev mode and scrapers
- Make sure Docker release CAN build
- Add failing test to block releases
- Make sure `cargo test` fails and Docker release can NOT build
- Add hard-coded hash of 1 API key, with 1 week expiration
- (POC) Test with curl
- Manually create SQLite DB for API keys, add 1 hash
- Impl DB reads
- Remove hard-coded API key
- Make sure `cargo test` passes and Docker CAN build
- (MVP) Test with curl
- Impl and test DB init / migration
- Impl DB writes (Add / revoke keys) as CLI commands
- Implement API (Behind X-Email auth) for that, test with curl
- Set up mitmproxy or something to add X-Email header in dev env
- Implement web UI (Behind X-Email)
- (X) Add feature flags to ptth_relay.toml for dev mode and scrapers
- ( ) Make sure Docker release CAN build
- ( ) Add failing test to block releases
- ( ) Make sure `cargo test` fails and Docker release can NOT build
- ( ) Add hard-coded hash of 1 API key, with 1 week expiration
- ( ) (POC) Test with curl
- ( ) Manually create SQLite DB for API keys, add 1 hash
- ( ) Impl DB reads
- ( ) Remove hard-coded API key
- ( ) Make sure `cargo test` passes and Docker CAN build
- ( ) (MVP) Test with curl
- ( ) Impl and test DB init / migration
- ( ) Impl DB writes (Add / revoke keys) as CLI commands
- ( ) Implement API (Behind X-Email auth) for that, test with curl
- ( ) Set up mitmproxy or something to add X-Email header in dev env
- ( ) Implement web UI (Behind X-Email)
POC is the proof-of-concept - At this point we will know that in theory the
feature can work.

View File

@ -39,6 +39,7 @@ fn end_to_end () {
display_name: None,
},
],
iso: Default::default (),
};
let config = ptth_relay::config::Config::try_from (config_file).expect ("Can't load config");