🔧 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>, 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)] #[derive (Deserialize)]
pub struct Config { pub struct Config {
pub port: Option <u16>, pub port: Option <u16>,
pub servers: Vec <Server>, pub servers: Vec <Server>,
#[serde (flatten)]
pub iso: Isomorphic,
} }
} }
@ -39,6 +51,7 @@ pub struct Server {
pub struct Config { pub struct Config {
pub servers: HashMap <String, Server>, pub servers: HashMap <String, Server>,
pub iso: file::Isomorphic,
} }
impl TryFrom <file::Server> for Server { impl TryFrom <file::Server> for Server {
@ -68,6 +81,7 @@ impl TryFrom <file::Config> for Config {
Ok (Self { Ok (Self {
servers, servers,
iso: f.iso,
}) })
} }
} }

View File

@ -495,6 +495,12 @@ async fn reload_config (
(*config) = new_config; (*config) = new_config;
debug! ("Loaded {} server configs", config.servers.len ()); 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 (()) Ok (())
} }

View File

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

View File

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