From 5badbfbefae8b637f5062ef4f708f7016cfde29b Mon Sep 17 00:00:00 2001 From: Mark Drobnak Date: Tue, 11 Aug 2020 14:37:32 -0400 Subject: [PATCH] docs: Add a sample config for autopush and fix some settings (#216) * Add a sample config for autopush and fix some settings - Removed unused `debug` setting - Added default for `endpoint_hostname` - Fixed invalid default for `crypto_key` * Use a dummy crypto_key value which will crash if used This prevents accidentally using no Fernet key in production. --- autopush/src/server/mod.rs | 2 - autopush/src/settings.rs | 16 +++---- configs/autopush.toml.sample | 83 ++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 13 deletions(-) create mode 100644 configs/autopush.toml.sample diff --git a/autopush/src/server/mod.rs b/autopush/src/server/mod.rs index f92acc0c7..bec7c1e3d 100644 --- a/autopush/src/server/mod.rs +++ b/autopush/src/server/mod.rs @@ -130,7 +130,6 @@ impl AutopushServer { } pub struct ServerOptions { - pub debug: bool, pub router_port: u16, pub port: u16, pub fernet: MultiFernet, @@ -172,7 +171,6 @@ impl ServerOptions { let router_url = settings.router_url(); let endpoint_url = settings.endpoint_url(); Ok(Self { - debug: settings.debug, port: settings.port, fernet, router_port: settings.router_port, diff --git a/autopush/src/settings.rs b/autopush/src/settings.rs index 02aae23e0..9762d3c7e 100644 --- a/autopush/src/settings.rs +++ b/autopush/src/settings.rs @@ -27,7 +27,6 @@ fn include_port(scheme: &str, port: u16) -> bool { #[derive(Debug, Default, Deserialize)] pub struct Settings { - pub debug: bool, pub port: u16, pub hostname: Option, pub resolve_hostname: bool, @@ -43,7 +42,7 @@ pub struct Settings { pub max_connections: u32, pub close_handshake_timeout: u32, pub endpoint_scheme: String, - pub endpoint_hostname: Option, + pub endpoint_hostname: String, pub endpoint_port: u16, pub crypto_key: String, pub statsd_host: String, @@ -73,8 +72,9 @@ impl Settings { s.set_default("max_connections", 0)?; s.set_default("close_handshake_timeout", 0)?; s.set_default("endpoint_scheme", "http")?; + s.set_default("endpoint_hostname", "localhost")?; s.set_default("endpoint_port", 8082)?; - s.set_default("crypto_key", Fernet::generate_key())?; + s.set_default("crypto_key", format!("[{}]", Fernet::generate_key()))?; s.set_default("statsd_host", "localhost")?; s.set_default("statsd_port", 8125)?; s.set_default("megaphone_poll_interval", 30)?; @@ -112,13 +112,7 @@ impl Settings { } pub fn endpoint_url(&self) -> String { - let url = format!( - "{}://{}", - self.endpoint_scheme, - self.endpoint_hostname - .as_ref() - .expect("Endpoint hostname must be supplied"), - ); + let url = format!("{}://{}", self.endpoint_scheme, self.endpoint_hostname,); if include_port(&self.endpoint_scheme, self.endpoint_port) { format!("{}:{}", url, self.endpoint_port) } else { @@ -171,7 +165,7 @@ mod tests { #[test] fn test_endpoint_url() { let mut settings: Settings = Default::default(); - settings.endpoint_hostname = Some("testname".to_string()); + settings.endpoint_hostname = "testname".to_string(); settings.endpoint_port = 80; settings.endpoint_scheme = "http".to_string(); let url = settings.endpoint_url(); diff --git a/configs/autopush.toml.sample b/configs/autopush.toml.sample new file mode 100644 index 000000000..2e324fcca --- /dev/null +++ b/configs/autopush.toml.sample @@ -0,0 +1,83 @@ +# The host to use for HTTP connections. Defaults to the machine's hostname. +#hostname = "localhost" + +# The WebSocket port +#port = 8080 + +# If the hostname should be resolved to an IP +#resolve_hostname = false + +# If human-readable logging should be used +#human_logs = false + +# The HTTP router host. Defaults to the hostname setting. +#router_hostname = "localhost" + +# The HTTP router port +#router_port = 8081 + +# Path to the SSL key to use for the router HTTP server. If not set, only HTTP +# connections are supported. +#router_ssl_key = "..." + +# Path to the SSL cert to use for the router HTTP server. Required if +# router_ssl_key is set. +#router_ssl_cert = "..." + +# Optional path to Diffie-Hellman parameters to use during SSL key exchange +#router_ssl_dh_param = "..." + +# The URI scheme to use for the endpoint server URL +#endpoint_scheme = "http" + +# The hostname of the endpoint server +#endpoint_hostname = "localhost" + +# The port of the endpoint server +#endpoint_port = 8082 + +# The URL to use for megaphone. If not set, megaphone functionality is disabled. +#megaphone_api_url = "..." + +# The token to use for megaphone. Required if megaphone_api_url is set. +#megaphone_api_token = "..." + +# The number of seconds between megaphone polls +#megaphone_poll_interval = 30 + +# The host of the metrics server. An empty string disables metrics. +#statsd_host = "localhost" + +# The port of the metrics server +#statsd_port = 8125 + +# Override the DynamoDB endpoint via the AWS_LOCAL_DYNAMODB environment +# variable. No default value. +#aws_ddb_endpoint = "..." + +# The name of the router table +#router_tablename = "router" + +# The prefix of the message table(s) +#message_tablename = "message" + +# A (stringified) list of Fernet keys to use when encrypting the notification +# endpoint URL. The default is a single auto-generated key. +#crypto_key = "[replace-me-with-a-real-key]" + +# How often we send WebSocket pings. 0 indicates no limit. +#auto_ping_interval = 300 + +# How long to wait for the WebSocket ping to come back before we time out. 0 +# indicates no limit. +#auto_ping_timeout = 4 + +# How long to wait for a closing handshake. 0 indicates no limit. +#close_handshake_timeout = 0 + +# Maximum number of WebSocket clients. 0 indicates no limit. +#max_connections = 0 + +# The max number of stored messages to return to a connecting client. If this +# limit is reached, the client is dropped and must re-register. +#msg_limit = 100